"My Location" in Google Maps javascript API
这个问题是半年前问的。是否更新了 Google Maps API v3 以使用在 http://maps.google.com 上找到的“我的位置”按钮?
我的位置是街景人和游戏 handle 外观控件之间的控件。
如果 Google Maps API 不提供我的位置,那么我是否需要使用 navigator.gelocation
编写我自己的 HTML5 地理定位功能,然后在 Google map 上创建我自己的控件?
最佳答案
No ,但是根据当前位置添加您自己的标记很容易:
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) {
// ...
});
}
关于html - 在 Google Maps API v3 上显示我的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9142833/