Немного расширил возможность кнопки 'Я на карте'. Теперь при загрузке карта должна центроваться по расположению пользователя. При уточнении координат карта перемещается вслед за точкой пользователя
This commit is contained in:
parent
1a06d9a950
commit
f65d1b5afe
|
|
@ -6,10 +6,11 @@ ymaps.ready(init);
|
|||
var myMap;
|
||||
var categories;
|
||||
var points = Array();
|
||||
var im;
|
||||
|
||||
function init() {
|
||||
myMap = new ymaps.Map("map", {
|
||||
center: [59.9, 30.3],
|
||||
center: [ymaps.geolocation.latitude, ymaps.geolocation.longitude],
|
||||
zoom: 9,
|
||||
behaviors: ['default', 'scrollZoom']
|
||||
});
|
||||
|
|
@ -36,6 +37,19 @@ function init() {
|
|||
myMap.balloon.close();
|
||||
}
|
||||
});
|
||||
|
||||
im = new ymaps.Placemark(
|
||||
[ymaps.geolocation.latitude, ymaps.geolocation.longitude],
|
||||
{
|
||||
balloonContentHeader: 'Вы здесь',
|
||||
balloonContent: ''
|
||||
},
|
||||
{
|
||||
iconImageHref: '/ico/man.png',
|
||||
iconImageSize: [32, 37]
|
||||
}
|
||||
);
|
||||
myMap.geoObjects.add(im);
|
||||
}
|
||||
|
||||
function getPoints()
|
||||
|
|
@ -112,47 +126,11 @@ function searchAdderess()
|
|||
|
||||
function showMeOnTheMap()
|
||||
{
|
||||
var userLat = 0;
|
||||
var userLng = 0;
|
||||
navigator.geolocation.getCurrentPosition(function(pos) {
|
||||
userLat = pos.coords.latitude;
|
||||
userLng = pos.coords.longitude;
|
||||
|
||||
myMap.geoObjects.add(
|
||||
new ymaps.Placemark(
|
||||
[userLat, userLng],
|
||||
{
|
||||
balloonContentHeader: ymaps.geolocation.country,
|
||||
balloonContent: ymaps.geolocation.city,
|
||||
balloonContentFooter: ymaps.geolocation.region
|
||||
},
|
||||
{
|
||||
iconImageHref: '/ico/man.png',
|
||||
iconImageSize: [32, 37]
|
||||
}
|
||||
)
|
||||
);
|
||||
myMap.setCenter([userLat, userLng]);
|
||||
}, function(){
|
||||
userLat = ymaps.geolocation.latitude;
|
||||
userLng = ymaps.geolocation.longitude;
|
||||
|
||||
myMap.geoObjects.add(
|
||||
new ymaps.Placemark(
|
||||
[userLat, userLng],
|
||||
{
|
||||
balloonContentHeader: ymaps.geolocation.country,
|
||||
balloonContent: ymaps.geolocation.city,
|
||||
balloonContentFooter: ymaps.geolocation.region
|
||||
},
|
||||
{
|
||||
iconImageHref: '/ico/man.png',
|
||||
iconImageSize: [32, 37]
|
||||
}
|
||||
)
|
||||
);
|
||||
myMap.setCenter([userLat, userLng]);
|
||||
im.geometry.setCoordinates([pos.coords.latitude, pos.coords.longitude]);
|
||||
});
|
||||
|
||||
myMap.setCenter(im.geometry.getCoordinates());
|
||||
}
|
||||
|
||||
function activateAddPoint()
|
||||
|
|
|
|||
Loading…
Reference in New Issue