0

我显示了一个特定位置的地图,地图上固定了兴趣点。这已经完成......我要做的是添加以下功能:如果用户位于此地图的现有范围内,则显示用户当前位置放大 10 并放置这些引脚。如果用户不在地图范围内,只需显示带有兴趣点图钉的地图。

我已经包含了一部分代码,无论地图的现有边界如何,都将显示用户位置,或者只显示没有用户位置的边界。你会看到我一直在玩弄这些功能却一无所获。

GeoMarker = new GeolocationMarker();
GeoMarker.setCircleOptions({fillColor: '#808080',fillOpacity:0.0,strokeOpacity:0.0});

google.maps.event.addListenerOnce(GeoMarker, 'position_changed', function() {
map.setCenter(this.getPosition());
//map.fitBounds(this.getBounds()); //uncomment to show based on user location regardless of the exsisting bounds of the map
//map.fitBounds(bounds); //uncomment to show ALL the listing Markers within the bounds of the map and not location of the user
//if (map.getZoom() > 1) map.setZoom(13); //this zoom is based on user location
// map.setCenter(this.getPosition());


var listener = google.maps.event.addListener(map, "idle", function() { 
google.maps.event.removeListener(listener); 
});
});

google.maps.event.addListener(GeoMarker, 'geolocation_error', function(e) {
alert('There was an error obtaining your position. Message: ' + e.message);
});
GeoMarker.setMap(map); 
}
4

1 回答 1

0

我不确定,如果我正确理解了您的问题,但是您可以通过 google.maps.Map.getBounds() 返回一个google.maps.LatLngBounds对象来获取当前视口的边界。在此调用中, contains() 方法传递用户的坐标以检查您的用户是否在边界内。

于 2013-04-19T16:53:19.983 回答