Show My Location on Google Maps API v3

后端 未结 4 1892
清酒与你
清酒与你 2020-12-04 22:33

"My Location" in Google Maps javascript API

This question was asked over half a year ago. Has Google Maps API v3 updated to use the \"My Location\" button

4条回答
  •  既然无缘
    2020-12-04 23:01

    //copy and paste this in your script section.
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(success, error);
    } else {
        alert('location not supported');
    }
    
    //callbacks
    function error(msg) {
        alert('error in geolocation');
    }
    
    function success(position) {
        var lats = position.coords.latitude;
        var lngs = position.coords.longitude;
        alert(lats);
        alert(lngs)
    };
    

提交回复
热议问题