0
我了解如何使用HTML5获取当前位置。单击按钮将使用Google Maps API V3的用户当前位置放置在地图上
如何添加点击处理程序,所以当按下按钮时,它会显示我在地图上的当前位置?
Google的例子很好地解释了它是如何完成的,但是按钮被设置为预定义的坐标。我如何将“Home”按钮附加到当前位置坐标上? Custom Control Example
我了解如何使用HTML5获取当前位置。单击按钮将使用Google Maps API V3的用户当前位置放置在地图上
如何添加点击处理程序,所以当按下按钮时,它会显示我在地图上的当前位置?
Google的例子很好地解释了它是如何完成的,但是按钮被设置为预定义的坐标。我如何将“Home”按钮附加到当前位置坐标上? Custom Control Example
从谷歌演示
navigator.geolocation.getCurrentPosition(function(position) {
initialLocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
map.setCenter(initialLocation);
由于initialLocation是全球性的,你可以用它来设置点击事件监听器:只需将地图设为initialLocation
google.maps.event.addDomListener(controlUI, 'click', function() {
map.setCenter(initialLocation)
});