Skip to content
Advertisement

How to get current position using html geo location with google maps api

I have this script to display markers on a google map, which works great but now I want to get current position to zoom in on map initially..

JavaScript

How do I pass the lat and long into the map?

JavaScript

It throws lat and long are not defined.

Advertisement

Answer

In the callback showPosition call the setPosition method of the map. As you have declared map within the initMap function perhaps declare the other functions also within the body of initMap

JavaScript

Or, declare use the callback function to initialise the map

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement