user525166
user525166

Reputation: 21

Problem in Google Map API...!

Hi there i'm currently working with google map api

for plotting multiple address with marker

i have written the following code as i understand the api function while study from google api documentation

for(var i=0; i<address.length; i++){
geocoder.getLocations(address[i],function(response){    
            if(response){
                place = response.Placemark[0];
                  point = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
                map.setCenter(point, 12);
                map.addOverlay(createmarker(point));
            }
});
}

createmarker is my function which works properly but the problem is this this place random markers with the address comes from address array sometimes 10, 12, 14, 14, and so on ....

I just want to plot all the address exists in my address array and on the google maps too..

so it must be fixed number of markers onto the map...!

So is there anyone who can help me for this issue..!

Thanks is advanced

Upvotes: 2

Views: 369

Answers (1)

Philar
Philar

Reputation: 3897

The createMarker function should look like this. Please see my example here, where you can add multiple markers on the map. Complete javascript can be found here.

function createMarker(latlng) {
   var contentString = html;
    var marker = new google.maps.Marker({
        position: latlng,
        map: map,
        zIndex: Math.round(latlng.lat()*-100000)<<5
    });

    google.maps.event.addListener(marker, 'click', function() {
        infowindow.setContent(contentString); 
        infowindow.open(map,marker);
    });
    marker.MyZoom = zoom; 
    return marker; 
}

Upvotes: 1

Related Questions