简体   繁体   中英

How to get current location in google map for web

I am new to this API. I generated api key but I don't know how to implement google map.

I searched a lot but nothing is working for me. I need help in finding users or device current location.

I need to display google map in my website with pointing to the current location of the device using angularjs.

Can anyone please suggest me how to get current location in google map or any tutorial where can I get code.

to get the current position you need to take location from the navigator itself with simple html5 geolocation code

<p id="demo"></p>


var x = document.getElementById("demo");
function getLocation() {
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(showPosition);
    } else {
        x.innerHTML = "Geolocation is not supported by this browser.";
    }
}
function showPosition(position) {
    x.innerHTML = "Latitude: " + position.coords.latitude + 
    "<br>Longitude: " + position.coords.longitude; 
}

after getting this location pass it on the map, your current location will be displayed

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM