2011-12-14 96 views
0

我想在谷歌地图上添加批量标记使用以下代码。直到我提供它properties_address阵列10个地址,但更多的则10个的地址给我下面的错误谷歌地图API添加更多,然后10个标记

var map = null; 
var geocoder = null; 
var bounds = null; 
var gdir; 

var properties_address = new Array(); 
var blueIcon = new GIcon(G_DEFAULT_ICON); 
blueIcon.iconSize = new GSize(26, 33); 
markerOptions = { icon:blueIcon }; 
blueIcon.image = "https://mysite/images/marker.gif"; 

properties_address = ["Abohar,Punjab,india", "Achhalda,Uttar Pradesh,india", "Achhnera,Uttar Pradesh,india", "Adari,Uttar Pradesh,india", "Adilabad,Andhra Pradesh,india", "Adipur,Gujarat,india", "Adoni,Andhra Pradesh,india", "Adoor,Kerala,india", "Agartala,Tripura,india", "Agra,Uttar Pradesh,india", "Ahmedabad,Gujarat,india", "Ahmedgarh,Punjab,india", "Ahmednagar,Maharashtra,india", "Aizawl,Mizoram,india", "Ajmer,Rajasthan,india", "Akaltara,Chhattisgarh,india", "Akola,Maharashtra,india", "Alappuzha,Kerala,india"]; 

$(document).ready(function() { 
    bounds = new GLatLngBounds; 
    initialize(); 
}); 

function initialize() { 
    if (GBrowserIsCompatible()) { 
     map = new GMap2(document.getElementById("map_canvas")); 
     map.setCenter(new GLatLng(21.88, 78.442626), 5); 
     geocoder = new GClientGeocoder(); 
     map.addControl(new GLargeMapControl()); 
     map.addControl(new GMapTypeControl()); 

     $.each(properties_address, function(index, property) { 
      showAddressByAddress(index, property, false); 
     });       
    } 
} 

function showAddressByAddress(index,address, is_custom) 
{ 
    if(address){ 
     geocoder.getLatLng(address,function(point) { 
      var marker = new GMarker(point,markerOptions); 
      map.addOverlay(marker); 
      bounds.extend(marker.getPoint()); 
      map.setZoom(map.getBoundsZoomLevel(bounds)); 
      map.setCenter(bounds.getCenter()); 

      GEvent.addListener(marker, "mouseover", function() { 
       if(!is_custom){ 
        address_html = address + '<br /><a id="route_'+index+'" href="#" class="route_url" data-address="'+ address +'">Route from here</a>'; 
       }else{ 
        address_html = address; 
       } 

       marker.openInfoWindowHtml(address_html); 
      });    

     }); 
    } 
} 

的代码是工作的罚款。

 
a is null 
http://maps.gstatic.com/intl/en_ALL/mapfiles/377a/maps2.api/main.js 
Line 1131 
+0

上面的示例代码是main.js吗? 'a'在哪里? – omarello 2011-12-14 16:13:36

+0

'a is null'是您在自己的代码中发生JS错误时从Google Maps JavaScript获得的典型错误。 – duncan 2011-12-14 17:43:19

回答

0

其固定的,我只是跳过未发现点通过地理编码。

function showAddressByAddress(index,address, is_custom) 
{ 
    if(address){ 
     geocoder.getLatLng(address,function(point) { 
      if(point){ 
       var marker = new GMarker(point,markerOptions); 

       map.addOverlay(marker); 
       bounds.extend(marker.getPoint()); 
       map.setZoom(map.getBoundsZoomLevel(bounds)); 
       map.setCenter(bounds.getCenter()); 


       GEvent.addListener(marker, "mouseover", function() { 
        if(!is_custom){ 
         address_html = address + '<br /><a id="route_'+index+'" href="#" class="route_url" data-address="'+ address +'">Route from here</a>'; 
        }else{ 
         address_html = address; 
        } 

        marker.openInfoWindowHtml(address_html); 
       }); 

      } 
     }); 
    } 
0

您是否尝试过使用萤火虫查看数组声音的属性,如其中一个项目的内容为空。

<html> 
<script type="text/javascript"> 
var myCars=["Saab","Volvo","BMW"];; 
console.log(myCars);  
</script> 
</html>` 

再看看在萤火控制台窗口查看阵列的属性 enter image description here

0

数组名是错误的:

var properties_add21ress = new Array();