Google maps api 3 如果用户在地图范围内,则显示位置;如果没有,请显示地图

Google maps api 3 如果用户在地图范围内,则显示位置;如果没有,请显示地图,google-maps-api-3,geolocation,Google Maps Api 3,Geolocation,我展示了一张特定位置的地图,地图上固定了兴趣点。这已经完成了。。。 我希望做的是添加以下功能: 如果用户位于此地图的现有边界内,则显示用户当前位置(放大为10),并将这些插脚放置到位。如果用户不在地图范围内,只需显示带有兴趣点的地图 我已经包含了我的代码的一部分,它要么显示用户的位置,而不管地图的现有边界,要么只显示没有用户位置的边界。你会发现我一直在玩弄这些功能,却一事无成 GeoMarker = new GeolocationMarker(); GeoMarker.setCircleOpti

我展示了一张特定位置的地图,地图上固定了兴趣点。这已经完成了。。。 我希望做的是添加以下功能: 如果用户位于此地图的现有边界内,则显示用户当前位置(放大为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); 
}

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