反向地理编码不适用于我的地图

时间:2012-06-01 05:31:19

标签: javascript google-maps-api-3 reverse-geocoding

我在google maps api v3上制作了一张地图,并尝试在地图上应用反向地理编码,但我无法使用地理编码地图加载我的地​​图。当我运行地图时,地图显示但地图上没有标记显示。这是我的地图链接和代码也是

她是地图代码

<script src="http://www.google.com/jsapi"></script>
    <script type="text/javascript">
      var script = '<script type="text/javascript" src="js/cluster';
      if (document.location.search.indexOf('compiled') !== -1) {
        script += '_compiled';
      }
      script += '.js"><' + '/script>';
      document.write(script);
    </script>

    <script type="text/javascript">
      google.load('maps', '3', {
        other_params: 'sensor=false'
      });
      google.setOnLoadCallback(initialize);
      var markerClusterer = null;
      var map = null;
      var geocoder;
      var markers = new Array(); 
      function initialize() {
       var GPS = [
{GPS:new google.maps.LatLng(34.019626247176,71.57975666079601), CNT:'Pakistan',REGION:'Peshawar',DIST:'Furqan Enterprises',SHOP:'Jamal Sweets',OWNER:'Ibrar Khan',MOBILE:'0300 989 9008',REGNO:'0000001',ICON:'1.png'},
{GPS:new google.maps.LatLng(34.02025371621,71.579215441513), CNT:'Pakistan',REGION:'Peshawar',DIST:'Furqan Enterprises',SHOP:'Usman Medicoz',OWNER:'Usman Hussain',MOBILE:'0344 905 1231',REGNO:'0000002',ICON:'1.png'},
];
      geocoder = new google.maps.Geocoder();    
      var map_center = new google.maps.LatLng(31.2330555556,72.3330555556);
      var myOptions = {
      zoom: 6,
      scaleControl:true,
      pancontrol: true,
      streetViewControl: true,
      center: map_center,
      mapTypeControl: true,
      mapTypeControlOptions: {
      style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
    },
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }    
    map = new google.maps.Map(document.getElementById("map"), myOptions);
     var infowindow = new google.maps.InfoWindow(); 
          if (markerClusterer) {
          markerClusterer.clearMarkers();
        }        
        for(i=0; i<GPS.length; i++)
         { 
           geocoder.geocode({'latLng': GPS[i].GPS}, function(results, status) {
           //map.setZoom(11);
           var markerImage = new google.maps.MarkerImage(imageUrl,
           new google.maps.Size(24, 32));
           var imageUrl = 'ico/' + GPS[i].ICON;        
           markers[i] = new google.maps.Marker({
           position: GPS[i].GPS,
           draggable: true,
           icon: markerImage,
           Info: '<table frame=box><tr><td align="Left"><font face="Arial" size=2 color=#336699>Shop Name:</td><td align="Left"><font face="Arial" size=2>'+ GPS[i].SHOP + '</font></td></tr><tr>'+
          '<td align="Left"><font face="Arial" size=2 color=#336699>Owner:</td><td align="Left"><font face="Arial" size=2>'+ GPS[i].OWNER + '</font></td></tr>'+
          '<td align="Left"><font face="Arial" size=2 color=#336699>Mobile:</td><td align="Left"><font face="Arial" size=2>'+ GPS[i].MOBILE + '</font></td></tr>'+
          '<tr><td align="Left"><font face="Arial" size=2 color=#336699>Distributer:</td><td align="Left"><font face="Arial" size=2>'+ GPS[i].DIST + '</font></td></tr><tr>'+
          '<tr><td align="Left"><font face="Arial" size=2 color=#336699>Region:</td><td align="Left"><font face="Arial" size=2>'+ GPS[i].REGION + '</font></td></tr>'+
          '<tr><td align="Left"></td><td align="Left"><font face="Arial" size=2 color=#336699><a target=_blank href=http://221.120.216.52/elp/sfpl.php?ccode=01&amp;&regno='+ GPS[i].REGNO +'>View</a></td></tr>'+
          '<tr><td align="Left"><font face="Arial" size=2 color=#336699>Region:</td><td align="Left"><font face="Arial" size=2>'+ results[1].formatted_address + '</font></td></tr>'+
          '</table>',
          title:GPS[i].SHOP + '(' +GPS[i].DIST + ')'
          });
          markers.push(markers);
          google.maps.event.addListener(markers[i], 'click', function() {
            infowindow.setContent(this.Info);
            infowindow.open(map,this);
            });
             }); 
        }
        zoom =  -1 ? null : -1;
        size =  -1 ? null : -1;
        markerClusterer = new MarkerClusterer(map, markers, {
          maxZoom: zoom,
          gridSize: size          
        });


      }
    </script>

Any One请帮我在infowindow上显示最近的坐标地址。

1 个答案:

答案 0 :(得分:1)

反向地理编码在每个国家都不起作用。请参阅Google提供的list of functionality coverage

如果“地理编码”表示“与图块相同”,则只能对图块上标识的位置进行地理编码,反向地理编码也受到限制。谷歌没有该国所有地方的详细信息。

这适用于巴基斯坦。

您也没有检查地理编码器返回的状态。它被传递给回调函数,你永远不会使用它。它几乎肯定会对正在发生的事情提供一些暗示。