Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
312 views
in Technique[技术] by (71.8m points)

javascript - How to add my location button in Google Maps?

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

map with 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?

question from:https://stackoverflow.com/questions/24952593/how-to-add-my-location-button-in-google-maps

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

Show My Location Control on Google Maps API v3

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...