这是我使用谷歌地图从位置检测ip的代码问题是我如何设置new google.maps.LatLng('< HERE >') to <div id="loc"></div>
?结果是 40.4652,-74.2307 #loc
<script>
function myMap() {
var mapProp= {
center: new google.maps.LatLng('<div id="loc"></div>'),
zoom:5,
};
var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
}
</script>
<Script>
$.get("https://ipinfo.io/104.238.132.170/json", function (response) {
$("#ip").html("IP: " + response.ip);
$("#loc").html("" + response.loc);
$("#region").html("" + response.region);
$("#country").html("" + response.country);
$("#address").html("Location: " + response.city + ", " + response.region);
$("#details").html(JSON.stringify(response, null, 4));
}, "jsonp");
</script>
<div id="googleMap" style="width:100%;height:400px;"></div>
答案 0 :(得分:0)
您可以提取纬度经度
[lat,lng] = $("#loc").html().split(',').map(parseFloat);
并将它们传递给google.maps.LatLng
var mapProp= {
center: new google.maps.LatLng(lat, lng)