Answer the question
In order to leave comments, you need to log in
How to fake yandex API location?
There is a code that determines the location of the site visitor, and output it to the created block:
ymaps.ready(init);
function init(){
ymaps.geolocation.get({
provider: 'yandex',
autoReverseGeocode: true
}).then(function (result) {
$('#urcity').html('Ваш город: <b style="margin-top: -50px;">'+result.geoObjects.get(0).properties.get('metaDataProperty.GeocoderMetaData.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.LocalityName')+'</b>');
});
}
function init() {
var geolocation = ymaps.geolocation,
myMap = new ymaps.Map('map', {
center: [55, 34],
zoom: 10
}, {
searchControlProvider: 'yandex#search'
});
geolocation.get({
provider: 'yandex',
mapStateAutoApply: true
}).then(function (result) {
result.geoObjects.options.set('preset', 'islands#redCircleIcon');
result.geoObjects.get(0).properties.set({
balloonContentBody: 'Мое местоположение'
});
myMap.geoObjects.add(result.geoObjects);
});
geolocation.get({
provider: 'browser',
mapStateAutoApply: true
}).then(function (result) {
result.geoObjects.options.set('preset', 'islands#blueCircleIcon');
myMap.geoObjects.add(result.geoObjects);
});
}
Answer the question
In order to leave comments, you need to log in
I may not understand the problem, but...
when initializing:
center: [55.74954, 37.621587],
or
ymaps.util.bounds.getCenterAndZoom(
,
[$mapElement.width (), $mapElement.height()]
)
or
center: res.geoObjects.get(0).geometry.getCoordinates(),
or after the fact:
setCenter(center[, zoom[, options]])
https://tech. yandex.ru/maps/archive/doc/jsapi/2.0/...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question