2012-04-27 24 views
0

我是新手谷歌地圖。我正在製作一張使用KmlLayer的地圖,顯示整個美國的銷售區域。這部分是成功的。我試圖在我的谷歌地圖上顯示所有家得寶

我現在想要顯示所有的家庭倉庫作爲標記,以便理論上可以訪問地圖,查看您的地區並查看您所在地區的所有家得寶。

這是我到目前爲止有:

$(document).ready(function() { 
    var map, geocoder; 

    init(); 

    $('.showVendors').click(function() { 
     loadKML(); 
     showVendors(); 
    }); 
}); 

function init() { 
    var myOptions = { 
     center: new google.maps.LatLng(37.09024,-95.712891), 
     zoom: 3, 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    }; 

    map = new google.maps.Map(document.getElementById('map'), myOptions); 
    geocoder = new google.maps.Geocoder(); 
} 

function loadKML() { 
    var kmlOptions = { 
     clickable: true, 
     map: map, 
     preserveViewport: true, 
     suppressInfoWindows: false 
    } 
    var kmlLayer = new google.maps.KmlLayer('kml/territories.kml', kmlOptions); 

} 

function showVendors() { 
    var vendor = 'Home Depot'; 
    geocoder.geocode({ 'premise' : vendor }, function(results, status) { 
     if (status == google.maps.GeocoderStatus.OK) { 
      map.setCenter(results[1].geometry.location); 
      var marker = new google.maps.Marker({ 
       map: map, 
       position: results[1].geometry.location 
      }); 
     } else { 
      alert ("Geocode was unsuccessful for the following reason: " + status); 
     } 
    }); 
} 

回答

1

當我直接通過API運行查詢:

http://maps.googleapis.com/maps/api/geocode/json?premise=Home%20Depot&sensor=true 

我得到:

{ 
    "results" : [], 
    "status" : "ZERO_RESULTS" 
} 

貌似這個信息在地理編碼API中不可用,這是您在上面使用的代碼。你將不得不與地方API運氣比較好,但它仍然是實驗:

https://developers.google.com/maps/documentation/places/

+0

谷歌提供的地方我一直在尋找的解決方案。感謝你把我推向正確的方向! – 2012-04-30 14:38:14

+0

不錯!很高興我能幫忙。 – javram 2012-04-30 14:45:37

相關問題