1

我从我的网页创建了一张地图,显示了某个位置的 ais-ships:

<!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>

我不想在代码中手动输入经度和纬度,而是希望将从例如 iPhone 检索到的 GPS 位置放在这些字段中。我已经尝试了几种解决方案,但我似乎没有得到正确的解决方案。有没有人有一个很好的解决这个问题的方法?

4

2 回答 2

2

您可以使用 HTML5 Geolocation 来获取 Lat、Long,但这会要求用户许可,如果用户拒绝,您的代码将失败。就是这样

if (navigator.geolocation) 
{
    navigator.geolocation.getCurrentPosition(function(position) 
    {  
        lat = position.coords.latitude;
        lon = position.coords.longitude; 
    }); 
} 
于 2012-06-28T09:07:05.230 回答
0

一些浏览器,包括 iPhone 浏览器,支持(草案)W3C navigator.geolocationAPI

于 2012-06-28T09:06:43.640 回答