fork download
  1. var currentPosition;
  2. function getCurrentPosition() {
  3.  
  4. if (navigator.geolocation) {
  5.  
  6. navigator.geolocation.getCurrentPosition(function (position) {
  7. currentPosition = [position.coords.latitude, position.coords.longitude];
  8.  
  9. var myGeoObject = new ymaps.GeoObject({
  10. geometry: {
  11. type: "Point",
  12. coordinates: currentPosition
  13. },
  14. properties: {
  15. iconContent: 'Мое местоположение'
  16. }
  17. }, {
  18. preset: 'twirl#nightStretchyIcon'
  19. });
  20.  
  21.  
  22. myMap.geoObjects.add(myGeoObject);
  23. myMap.setCenter(currentPosition, 14, {
  24. checkZoomRange: true
  25. });
  26. });
  27.  
  28. }
  29. else {
  30. alert("Geolocation API не поддерживается в вашем браузере");
  31. }
  32. }
  33.  
  34. getCurrentPosition();
  35. console.log(currentPosition);
Runtime error #stdin #stdout #stderr 0.01s 30424KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
prog.js:4:0 ReferenceError: navigator is not defined