我已经在我的项目中为地图试用了Google API。现在我需要获取用户选择的GPS坐标,以便将其存储在Mysql中。
<!DOCTYPE html>
<html>
<head lang="en">
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=myKeyQ&libraries=places"></script>
<title>Demo Maps</title>
</head>
<body>
<iframe
width="600"
height="450"
frameborder="0" style="border:0"
src="https://www.google.com/maps/embed/v1/place?key=myKey
&q=Space+Needle,Seattle+WA" allowfullscreen>
</iframe>
</body>
</html>
答案 0 :(得分:1)
在javascript中,您可以使用navigator.geolocation功能
<script>
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
window.alert( "Geolocation is not supported by this browser.");
}
}
function showPosition(position) {
window.alert( "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude);
}
getLocation();
</script>