在 Google Maps API v3 上显示我的位置 [英] Show My Location on Google Maps API v3

查看:20
本文介绍了在 Google Maps API v3 上显示我的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的位置"在 Google 地图 javascript API 中

这个问题是半年前问的.是否已更新 Google Maps 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆