【发布时间】:2018-10-31 16:12:14
【问题描述】:
我正在使用地理位置来获取用户的当前位置。问题是有时它不会返回准确的位置。然后我想允许用户在谷歌地图上的正确位置手动设置标记,然后返回这个新位置的经度和纬度。
请问有什么想法吗?
这是我在使用地理位置返回用户位置时使用的代码
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
}
else {
document.getElementById("location-x").innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
var latitude= position.coords.latitude;
var longitude= position.coords.longitude;
document.getElementById("location-x").innerHTML = "Latitude: " + latitude +
"<br>Longitude: " + longitude;
$("#latitude").val(latitude);
$("#longitude").val(longitude);
var uluru = {lat: latitude, lng: longitude};
$("#map").show();
var map = new google.maps.Map(
document.getElementById('map'), {zoom: 15, center: uluru});
var marker = new google.maps.Marker({position: uluru, map: map});
}
【问题讨论】:
标签: javascript html laravel google-maps