我有两个变量:纬度和经度: 我想像这样插入它。
<img src = "https://maps.googleapis.com/maps/api/staticmap?center=" + latitude + "," + longitude + "&zoom=15&size=640x640&scale=2&key=example";
这是我的代码:
<head>
<script type="text/javascript">
function TestGeo() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition( TestMap, error, {maximumAge: 30000, timeout: 10000, enableHighAccuracy: false} );
} else {
alert("Sorry, but it looks like your browser does not support geolocation.");
}
function TestMap(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;}
</script>
</head>
<body onload="TestGeo();">
<img src = "https://maps.googleapis.com/maps/api/staticmap?center=" + latitude + "," + longitude + "&zoom=15&size=640x640&scale=2&key=example";
</body>
</html>
答案 0 :(得分:0)
如果您使用的是javascript。试试这个
function TestMap(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
var imgsrc = "https://maps.googleapis.com/maps/api/staticmap?center="+latitude+","+longitude+"&zoom=15&size=640x640&scale=2&key=example";
$('#imgselector').attr('src', imgsrc)
}
html应该是
<img src="" id="imgselector"/>