如何在Google地图中添加我的位置按钮? [英] How to add my location button in Google Maps?

查看:207
本文介绍了如何在Google地图中添加我的位置按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以添加默认控件选项 我的位置 按钮。





有没有将其设为默认值的方法或者我需要使用地理位置创建按钮,然后触发该按钮上的click事件以便将用户导航到当前位置?

解决方案

我们为Google Maps API v3制作了这样一个组件。任何人都可以在自定义项目中添加一个显示当前地理位置的控件,只需一行代码:

  var geoloccontrol = new klokantech。 GeolocationControl(map,mapMaxZoom); 

在HTML标题中包含此JavaScript后:

 < script src =https://cdn.klokantech.com/maptilerlayer/v1/index.js>< / script> 

参见:





它将标准控件添加到地图中 - 一旦点击 - 它会显示您所在位置周围的蓝色圆圈,其大小来自可用位置数据的精度。如果你不拖动地图,它会让你在移动后保持定位。



这个控件是为由 http://www.maptiler.com/ 软件 - 为地图叠加层和由图像和栅格地理数据制作的自定义图层创建图块。



注意:这个答案是我们对在Google Maps API v3上显示我的位置


I'd like to know if it's possible to add as default controls option my location button.

Is there any way to make it as default or I need to make button with geolocation and then trigger the click event on that button in order to navigate user to the current location?

解决方案

We have made such a component for Google Maps API v3. Anybody can use in custom projects to add a control showing current geolocation with just one line of code:

var geoloccontrol = new klokantech.GeolocationControl(map, mapMaxZoom);

after including in the HTML header this JavaScript:

<script src="https://cdn.klokantech.com/maptilerlayer/v1/index.js"></script>

See:

http://www.maptiler.com/maptilerlayer/

for an example code and documentation.

It adds the standard control to the map - and once tapped - it shows the blue circle around your location with size derived from precision of the location data available. If you don't drag the map it will keep you positioned once you move.

This control has been developed for viewer automatically generated by http://www.maptiler.com/ software - which creates tiles for map overlays and custom layers made from images and raster geodata.

Note: this answer is a repost of our response from Show My Location on Google Maps API v3

这篇关于如何在Google地图中添加我的位置按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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