Version:
Popular examples
Map
Geo objects
Balloon and hint
Controls
Hotspots
Clustering
GeoQuery
Behaviors and events
Search on a map
Traffic
User's location
Routing
YMapsML
GeoXML
ObjectManager
Modular system
Panoramas
External modules

Creating a map with the user's location

Save as filesEdit on JSFiddle

This example demonstrates how to create a map that is initially centered on the user's location.

The "get" method of the geolocation function is used for detecting the location. In the parameters, you can set the preferred method of location detection (by IP or using the Geolocation API), the time to wait for a response, and so on. For more information, see the description of the method.

When calling this method, the browser tries to determine the geographical position of the user. If successful, the result is written in the geoObjects map field; otherwise, there is an error message.

In this example, if the location cannot be detected, a map is created with the center in Moscow.

Пишете на JavaScript? У нас есть вакансии
Mon Oct 31 2022 13:07:25 GMT+0300 (Moscow Standard Time)