我第一次尝试在主页上包含谷歌地图,刚刚找到了创建具有特定位置的谷歌地图的代码 -
var myLatlng1 = new google.maps.LatLng(53.65914, 0.072050)
并且我不知道如何更改标记所在的位置 - 在哪里可以找到位置坐标?谢谢!
<html>
<head>
<title> Map </title>
<style>
html, body, #map-canvas {
margin: 0;
padding: 0;
height: 500px;
width: 800px;}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false">
</script>
<script>
var map;
function initialize()
{
var myLatlng1 = new google.maps.LatLng(53.65914, 0.072050);
var mapOptions =
{
zoom: 10,
center: myLatlng1,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
<?php
$sql = mysql_query("SELECT * FROM data ORDER BY ID DESC");
while($row =mysql_fetch_array($sql))
{
$desc = $row['DESCRIPTION'];
$location = $row['LOCATION'];
$counter += 1;
?>
var marker = new google.maps.Marker({
position: new google.maps.LatLng(<?php echo $location; ?>),
map: map,
title: '<?php echo $desc; ?>',
icon: '/image/cam.png'
});
navigator.geolocation.getCurrentPosition(showPosition);
}
var showPosition = function (position)
{
map.setCenter(new google.maps.LatLng(position.coords.latitude,
position.coords.longitude), 16);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
最佳答案
这很容易。首先转到谷歌地图并选择您要放大的位置。查看页面顶部的 url 后,它应该如下所示:
https://www.google.com/maps/@44.0005355,-71.0799974,12z
这是您的经纬度 44.0005355 和 -71.0799974 只需将它们替换为您拥有的值即可。
关于javascript - 引用谷歌地图中的特定位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36480894/