Robert Nilsen
Robert Nilsen

Reputation: 11

Marine Traffic Map - Latitude/Longitude Javascript

I have created a map from my webpage showing ais-ships in a certain location:

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

Instead of punching in the longitude and latitude manually in the code, I wish to put the GPS position retrieved from for example an iPhone in these fields. I've tried several solutions, but I don't seem to get it right. Does anyone have a good solution to this problem?

Upvotes: 1

Views: 2042

Answers (2)

Nhu Trinh
Nhu Trinh

Reputation: 13966

You can use HTML5 Geolocation to get Lat,Long, but that will ask user for permission and your code will fail if user reject. Here's how

if (navigator.geolocation) 
{
    navigator.geolocation.getCurrentPosition(function(position) 
    {  
        lat = position.coords.latitude;
        lon = position.coords.longitude; 
    }); 
} 

Upvotes: 2

Will
Will

Reputation: 75665

Some browsers, including the iPhone browser, support a (draft) W3C navigator.geolocation API.

Upvotes: 0

Related Questions