我已经在我的网页上创建了一张地图,显示了某个地点的船只:
<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
width='40%'; //the width of the embedded map in pixels or percentage
height=430; //the height of the embedded map in pixels or percentage
border=1; //the width of border around the map. Zero means no border
notation=false; //true or false to display or not the vessel icons and
//options at the left
shownames=false; //true or false to dispaly ship names on the map
latitude=59.01; //the latitude of the center of the map in decimal degrees
longitude=5.78; //the longitude of the center of the map in decimal degrees
zoom=10; //the zoom level of the map. Use values between 2 and 17
maptype=3;
trackvessel=0; //the MMSI of the vessel to track, if within the range
fleet=''; //the registered email address of a user-defined fleet
remember=false;
scale=2;
</script>
<script type="text/javascript" src="http://www.marinetraffic.com/ais/embed.js">
</script>
</body>
</html>
我不想在代码中手动打入经度和纬度,而是希望将GPS位置从例如iPhone中检索到这些字段中。我已经尝试了几种解决方案,但我似乎没有做对。有没有人能很好地解决这个问题?
答案 0 :(得分:2)
您可以使用HTML5 Geolocation获取Lat,Long,但这会要求用户获得许可,如果用户拒绝,您的代码将失败。这是
的方式if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(function(position)
{
lat = position.coords.latitude;
lon = position.coords.longitude;
});
}
答案 1 :(得分:0)
某些浏览器(包括iPhone浏览器)支持(草稿)W3C navigator.geolocation
API。