Google maps 在标记出数据库的同时,在谷歌地图上显示用户的当前位置

Google maps 在标记出数据库的同时,在谷歌地图上显示用户的当前位置,google-maps,userlocation,Google Maps,Userlocation,我使用了这个链接中的代码 我想显示用户的当前位置,以便用户可以看到他们附近有哪些标记。本教程不显示用户位置,而是使用坐标center:new google.maps.LatLng(47.6145,-122.3418) 我试过:center:newgoogle.maps.LatLng(position.coords.lation,position.coords.longitude)但它不起作用 知道我做错了什么吗?克莱顿,使用navigator.geolocation.getCurrentPosi

我使用了这个链接中的代码

我想显示用户的当前位置,以便用户可以看到他们附近有哪些标记。本教程不显示用户位置,而是使用坐标
center:new google.maps.LatLng(47.6145,-122.3418)

我试过:
center:newgoogle.maps.LatLng(position.coords.lation,position.coords.longitude)但它不起作用


知道我做错了什么吗?

克莱顿,使用navigator.geolocation.getCurrentPosition方法提供回调函数:

var map = new google.maps.Map(document.getElementById("map"), mapOptions);
if(navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(
        function(position) {
            map.setCenter(new google.maps.LatLng(position.coords.latitude,position.coords.longitude));
        }
       ,function() {
            alert("Geolocation service failed");
        });
}
else
    alert("Your browser doesn't support geolocation");

你认为这个职位来自哪里?反应的最大thx。如何在我从这个链接[link]使用的代码中实现这个代码