Matt6607699
Posts: 0
Joined: Sat Jan 25, 2014 7:18 am

Create new infoWindow for multiple markers generated from REST.

I have run through all of the related topics but cant find a working solution.
I am generating Markers from saved DB coordinates which is working fine.
I would like a new popup infoWindow for each marker but I can only get the window to display one of the results no matter which I click. on hover each marker correctly shows its cooresponding name. Is there something that I can add to my code to get a new window for each Marker that displays its specific info? I'm getting no debugger errors. The app name is Hapsy, its been shared with support previously.

This is what I'm using:

var response = JSON.stringify(data);
localStorage.setItem("json_response", response);
var list_coordinate = localStorage.getItem('json_response');
var coordsArray = JSON.parse(list_coordinate);
var marker;
var myLat = localStorage.getItem('local_geo_lat');
var myLong = localStorage.getItem('local_geo_long');
var myLatlng = new google.maps.LatLng(myLat,myLong);
var mapOptions = {
zoom: 5,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};

for (var i = 0, j = coordsArray.length; i < j; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng( coordsArray.lat, coordsArray.long ),
title: coordsArray.name,
map: Appery("map").gmap,
});
var infowindow = new google.maps.InfoWindow({content: coordsArray.name});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(Appery("map").gmap,marker);
});
}
Appery("map").options.mapElement.gmap('addMarker', marker);
Appery("map").options.mapElement.gmap(mapOptions);
Appery("map").options.mapElement.gmap("refresh");

Image

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

Create new infoWindow for multiple markers generated from REST.

Hi.

Please use the following code:

pre
var CreateMarker = function(coordsArray, i){
var marker = new google&#46;maps&#46;Marker({
position: new google&#46;maps&#46;LatLng( coordsArray&#46;lat, coordsArray&#46;long ),
title: coordsArray&#46;name,
map: Appery("map")&#46;gmap,
});

Code: Select all

 var infowindow = new google&#46;maps&#46;InfoWindow({content: coordsArray[i]&#46;name});  

 google&#46;maps&#46;event&#46;addListener(marker, 'click', function() {  
     infowindow&#46;open(Appery("map")&#46;gmap,marker);  
 });  

};

for (var i = 0, j = coordsArray&#46;length; i < j; i++)
CreateMarker(coordsArray, i);
/pre
Instead of yours:

pre
for (var i = 0, j = coordsArray&#46;length; i < j; i++) {
marker = new google&#46;maps&#46;Marker({
position: new google&#46;maps&#46;LatLng( coordsArray&#46;lat, coordsArray&#46;long ),
title: coordsArray&#46;name,
map: Appery("map")&#46;gmap,
});
var infowindow = new google&#46;maps&#46;InfoWindow({content: coordsArray&#46;name});
google&#46;maps&#46;event&#46;addListener(marker, 'click', function() {
infowindow&#46;open(Appery("map")&#46;gmap,marker);
});
}
/pre
Also please look at the topic http://javascriptissexy.com/javascrip...

Matt6607699
Posts: 0
Joined: Sat Jan 25, 2014 7:18 am

Create new infoWindow for multiple markers generated from REST.

Thank you so much for the help!
I received a TypeError: a is undefined on my debugger but couldnt find any a in your new code. I'm sure its a fault on my end somehow but I cant seem to find it...
Image

Nikita
Posts: 0
Joined: Fri Feb 28, 2014 4:02 pm

Create new infoWindow for multiple markers generated from REST.

Hi Matt!

What is a line of code, that produce this error?

Matt6607699
Posts: 0
Joined: Sat Jan 25, 2014 7:18 am

Create new infoWindow for multiple markers generated from REST.

Firebug didnt give a line for the Error but I commented out each section of code and excluding the following(bottom of code):
Appery("map").options.mapElement.gmap('addMarker', marker);
Appery("map").options.mapElement.gmap(mapOptions);
Appery("map").options.mapElement.gmap("refresh");

got rid of the error.
Again thank you so much for your help with those infoWindows.

Image

Igor
Posts: 0
Joined: Tue Apr 02, 2013 12:05 pm

Create new infoWindow for multiple markers generated from REST.

Lets try to move a line of code:

pre
code
Appery("map")&#46;options&#46;mapElement&#46;gmap('addMarker', marker);
/code
/pre

to the end of "CreateMarker" function.

Matt6607699
Posts: 0
Joined: Sat Jan 25, 2014 7:18 am

Create new infoWindow for multiple markers generated from REST.

Code added to end of the CreateMarker() and all seems to work great! Thank you for your help

Matt6607699
Posts: 0
Joined: Sat Jan 25, 2014 7:18 am

Create new infoWindow for multiple markers generated from REST.

Ok so now I've run into another issue that I cant solve. I need to remove the markers from the map at the user selects different search radius. The radius REST call work fine but I need to have the markers removed at each new search. Google says I need to iterate through my array and delete/hide one at a time but everything I try doesn't work. I addded this to the end of the code above but no luck...
var SearchB = Appery('show_on_map_button');

google.maps.Map.prototype.clearMarkers = function() {
for(var i=0; i < coordsArray.length; i++){
coordsArray.setMap(null);
}
coordsArray = new Array();
};

$(SearchB).click(google.maps.Map.prototype.clearMarkers());

I always get an error on the setMap() google function as undefined.

Matt6607699
Posts: 0
Joined: Sat Jan 25, 2014 7:18 am

Create new infoWindow for multiple markers generated from REST.

I tried using this too with no luck. I don't get any errors in Firebug but the Markers do not go away:

var SearchB = Appery('show_on_map_button');

var coordsArray = [];
// Deletes all markers in the array by removing references to them
function deleteOverlays() {
if (coordsArray) {
for (i in coordsArray) {
coordsArray.setMap(null);
}
coordsArray.length = 0;
}
}
$(SearchB).click(deleteOverlays());

//and I added coordsArray.push(marker); to the CreateMarker function.

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

Create new infoWindow for multiple markers generated from REST.

Hi Matt,

To remove certain marker from the map, please use following code:

premarker&#46;setMap(null);/pre

Also we recommend to read markers documentation: https://developers.google.com/maps/do...

Return to “Issues”