0

在尝试进一步实施之前,我一直在 Google Code Playground 中对此进行测试。

这只是在地图上放置一个地图标记,并通过以英里为单位的半径生成一个圆形覆盖。但是,我仍然无法使其正常工作。

它似乎打破了圆圈覆盖的创建。我一直在寻找解决方案,但到目前为止我尝试过的一切要么中断(地图不显示),要么没有结果(没有圆圈覆盖)。

注意:我遇到了一个类似的问题 [question:] Circle overlay in Google Map V3 API js。我尝试了这个解决方案,但没有奏效。

function initialize()
{
  if (GBrowserIsCompatible())
  {
    var map = new GMap2(document.getElementById("map_canvas"));
    map.setCenter(new GLatLng(30.6957, -88.1813), 13);


    var latlng = new GLatLng(30.6957, -88.1813);
    map.addOverlay(new GMarker(latlng));

    var draw_circle = null;

    function Draw_Circle(Miles)
    { 
      Miles *= 1600;

      if (draw_circle != null)
      {
        draw_circle.setMap(null);
      }

      draw_circle = new google.maps.Circle({
        center: latlng,
        radius: Miles,
        strokeColor: "#FF0000",
        strokeOpacity: 0.8,
        strokeWeight: 2,
        fillColor: "#FF0000",
        fillOpacity: 0.35,
        map: map
      });  
    }

    Draw_Circle(15);
  }
 }

再次提前感谢您。

编辑:现在我被告知我正在混合 API 版本。我想出了以下内容:

var latLng;

function initialize() {
  var map;
  var mapDiv = document.getElementById('map-canvas');
  map = new google.maps.Map(mapDiv, {
    center: new google.maps.LatLng(30.6957, -88.1813),
    zoom: 13,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  });

  latLng = new google.maps.LatLng(30.6957, -88.1813);
  var marker = new google.maps.Marker({
      position: latLng,
      map: map
    });

  var draw_circle = null;

  function Draw_Circle(Miles)     
  {        
    Miles *= 1600;        
    if (draw_circle != null)       
    {         
      draw_circle.setMap(null);       
    }       

    draw_circle = new google.maps.Circle({         
      center: latlng,         
      radius: Miles,         
      strokeColor: "#FF0000",         
      strokeOpacity: 0.8,         
      strokeWeight: 2,         
      fillColor: "#FF0000",         
      fillOpacity: 0.35,         
      map: map       
     });

  }      

  Draw_Circle(15);
}

我几乎在那里......现在,我没有来自调试器的任何错误消息来表示我的圆圈覆盖有什么问题。

4

1 回答 1

1

问题 1:您同时使用Google Maps API V2Google Maps API V3

问题2:在以下代码中

.....
draw_circle = new google.maps.Circle({         
  center: latlng,   
  .....

抛出的错误是ReferenceError: latlng is not defined.

如果替换latlnglatLng,脚本将按预期工作。

于 2012-11-30T09:44:25.440 回答