在Google Maps API v3上显示我的位置 [英] Show My Location on Google Maps API v3
问题描述
"我的位置"在Google Maps JavaScript API中
这个问题在半年前被问过。 Google地图API v3更新为使用 http://maps.google.com
This question was asked over half a year ago. Has Google Maps API v3 updated to use the "My Location" button found on http://maps.google.com?
我的位置是街景视图控制器和游戏手柄控件之间的控件。
My Location is the control between the Street View man and the gamepad-looking controls.
如果Google Maps API不提供我的位置,那么我需要使用 navigator.gelocation
编写自己的HTML5地理位置功能,然后在Google地图上创建自己的控件?
If Google Maps API doesn't provide My Location then do I need to write my own HTML5 geolocation feature using navigator.gelocation
then create my own control on Google Maps?
推荐答案
否,但根据当前位置添加您自己的标记很容易:
No, but adding your own marker based on current location is easy:
var myloc = new google.maps.Marker({
clickable: false,
icon: new google.maps.MarkerImage('//maps.gstatic.com/mapfiles/mobile/mobileimgs2.png',
new google.maps.Size(22,22),
new google.maps.Point(0,18),
new google.maps.Point(11,11)),
shadow: null,
zIndex: 999,
map: // your google.maps.Map object
});
if (navigator.geolocation) navigator.geolocation.getCurrentPosition(function(pos) {
var me = new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude);
myloc.setPosition(me);
}, function(error) {
// ...
});
这篇关于在Google Maps API v3上显示我的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!