2012-05-21 8 views
5

से Google मानचित्र पर एकाधिक मार्कर लगाकर मैं एक सरणी से प्रदान किए गए मानचित्र पर एकाधिक मार्कर लगाने की कोशिश कर रहा हूं। अभी अभी केवल मेरा प्रारंभिक बिंदु भार (एनवाईसी)।सरणी

var geocoder; 
var map; 
var markersArray = []; 

//plot initial point using geocode instead of coordinates (works just fine) 
    function initialize() { 
    geocoder = new google.maps.Geocoder(); 
    latlang = geocoder.geocode({ 'address': 'New York City'}, function(results, status) { //use latlang to enter city instead of coordinates 
      if (status == google.maps.GeocoderStatus.OK) { 
       map.setCenter(results[0].geometry.location); 
       marker = new google.maps.Marker({ 
       map: map, 
       position: results[0].geometry.location 
       }); 
      markersArray.push(marker); 
      } 
      else{ 
      alert("Geocode was not successful for the following reason: " + status); 
      } 
     }); 
    var myOptions = { 
     center: latlang, zoom: 5, mapTypeId: google.maps.MapTypeId.SATELLITE, 
     navigationControlOptions: { 
      style: google.maps.NavigationControlStyle.SMALL 
     } 
    }; 
    map = new google.maps.Map(document.getElementById("map_canvas"), 
     myOptions); 

    } 

/////////////////////////////////////////////////////////// 
//Everything below this line is for attempting to plot the markers 

    var locationsArray = ['Pittsburgh','Chicago', 'Atlanta']; 

    function plotMarkers(){ 
for(var i = 0; i < locationsArray.length; i++){ 
    codeAddresses(locationsArray[i]); 
} 
    } 

    function codeAddresses(address){ 
    geocoder.geocode({ 'address': address}, function(results, status) { 
      if (status == google.maps.GeocoderStatus.OK) { 
       map.setCenter(results[0].geometry.location); 
       marker = new google.maps.Marker({ 
       map: map, 
       position: results[0].geometry.location 
       }); 
      //markersArray.push(marker); 
      } 
      else{ 
      alert("Geocode was not successful for the following reason: " + status); 
      } 
    }); 
    } 
+1

आपको अपनी समस्या के बारे में अधिक जानकारी प्रदान करने की आवश्यकता है क्या आपको कुछ अपवाद मिल रहा है? – Jorge

उत्तर

5

आप वास्तव में ऊपर टुकड़ा कहीं plotMarkers बुला नहीं कर रहे हैं! जब मैंने प्रारंभ करने के अंत में जोड़ा (नक्शा परिभाषित करने के बाद) यह बहुत अच्छा काम करता है! http://jsfiddle.net/T5aKE/

 ... 
     map = new google.maps.Map... 
     plotMarkers(); 
     ... 
+0

वाह, विश्वास नहीं कर सकता कि मुझे ऐसी स्पष्ट गलती याद आई। मुझे हमेशा आंखों के दूसरे सेट की आवश्यकता होती है! धन्यवाद! – user1104854