在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) {
    // ...
});