diff --git a/public/js/main.js b/public/js/main.js index b79b538..f1f210e 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -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()