簡體   English   中英

Google映射自定義標記問題

[英]Google maps custom markers issues

我正在嘗試在Google地圖上可視化一些融合表數據。 我有一些記錄,其中地址按區域號分組。 基本上我想發生的是以下內容:

  1. 我從英尺拉數據
  2. 對於每條記錄,我對地址進行地理編碼並根據區域號分配自定義標記
  3. 我可以將按不同標記分組的所有不同記錄可視化

到目前為止,這是我所做的:

這是對ft查詢

var query = "SELECT 'Full Address' , Territory FROM " + tableid;
          query = encodeURIComponent(query);
          var gvizQuery = new google.visualization.Query(
              'http://www.google.com/fusiontables/gvizdata?tq=' + query);

現在我要詳細說明查詢數據

gvizQuery.send(function(response) {
      var numRows = response.getDataTable().getNumberOfRows();
      // For each row in the table, create a marker
      for (var i = 0; i < numRows; i++) {
        var stringaddress = response.getDataTable().getValue(i, 0);
        var territory = response.getDataTable().getValue(i,1);
        **latlng**(stringaddress,
        function(data){
          console.log(data);
          **createMarker**(data,territory,stringaddress);//callback
        });
      }
    });

這是latlng函數:從字符串地址返回google maps點

function latlng(address,callback){
        var latlng;
        var geocoder = new google.maps.Geocoder();
        geocoder.geocode({
            "address": address
        }, function(results,status) {
           if ( status == google.maps.GeocoderStatus.OK ) { 
            latlng= new google.maps.LatLng(results[0].geometry.location.lat(), results[0].geometry.location.lng());
            callback(latlng);
           }
        });
    }

最后是創建標記功能

var createMarker = function(coordinate, territory,address) {
        console.log("now drawing marker for " + coordinate + "found in territory number " + territory);
        var markerpath="images/icon"+territory+".png";
          var marker = new google.maps.Marker({   
            map: map,
            position: coordinate,
            icon: new google.maps.MarkerImage(markerpath)
          });
          google.maps.event.addListener(marker, 'click', function(event) {
            infoWindow.setPosition(coordinate);
            infoWindow.setContent('Address: ' + address + '<br>Territory = ' + territory);
            infoWindow.open(map);
          });
        };

我面臨的問題是, 盡管我應該為ft的每條記錄調用createmarker函數 ,但實際上它只被調用了兩次 (共250次), 並且只代表一個地區 (數字7)。 我在想什么 謝謝您的幫助!

地理編碼器受速率限制和配額的限制,大約10次地理編碼操作后,您將看到OVER_QUERY_LIMIT返回的狀態(您的代碼會默默忽略)。 要查看問題,請記錄返回的狀態:

function latlng(address,callback){
    var latlng;
    var geocoder = new google.maps.Geocoder();
    geocoder.geocode({
        "address": address
    }, function(results,status) {
       if ( status == google.maps.GeocoderStatus.OK ) { 
        latlng= new google.maps.LatLng(results[0].geometry.location.lat(), results[0].geometry.location.lng());
        callback(latlng);
       } else {
         console.log("geocode failed: "+status);
       }
    });
}

(或者您可以添加警報,這對於200個標記來說確實很煩人)

您需要適當地處理OVERY_QUERY_LIMIT(限制您的請求),但這可能會使地圖加載速度太慢。

最佳選擇 :離線對地址進行地理編碼,並將坐標存儲在FusionTable中,在查詢中返回它們,然后使用它們來顯示標記。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM