Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Geolocation API on the iPhone

Does anyone know whether the iPhone supports or will soon support the W3C Geolocation specification?

I'm looking to build an app for mobile users, but rather than spend the time developing apps for every different platform (iPhone, Android, etc...), I'd much prefer to create a web app that makes use of the W3C Standard.

like image 935
Codebeef Avatar asked Oct 21 '08 12:10

Codebeef


People also ask

How do I get geolocation on my iPhone?

Here's how: Go to Settings > Privacy, then select Location Services. Select an app, then turn Precise Location on or off.

Does Apple maps have API?

The Apple Maps Server API requires authorization using a JSON Web Token (JWT) for API calls. You obtain a key for creating the token when you complete the setup in your Apple Developer account. The Apple Maps Server API is a web-based API similar to the MapKit JS API, and uses the same authorization infrastructure.

How do I use Geolocation API?

The Geolocation API is accessed via a call to navigator. geolocation ; this will cause the user's browser to ask them for permission to access their location data. If they accept, then the browser will use the best available functionality on the device to access this information (for example, GPS).

How do I enable geolocation?

Open your phone's Settings app. Under "Personal," tap Location access. At the top of the screen, turn Access to my location on or off.


1 Answers

This code worked for me -- on the iPhone web browser Safari and as an added bonus it even worked with FireFox 3.5 on my laptop! The Geolocation API Specification is part of the W3 Consortium’s standards But be warned: it hasn’t been finalized as yet.

alt text
(source: bemoko.com)alt text
(source: bemoko.com)

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Geolocation API Demo</title> <meta content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" name="viewport"/> <script> function successHandler(location) {     var message = document.getElementById("message"), html = [];     html.push("<img width='256' height='256' src='http://maps.google.com/maps/api/staticmap?center=", location.coords.latitude, ",", location.coords.longitude, "&markers=size:small|color:blue|", location.coords.latitude, ",", location.coords.longitude, "&zoom=14&size=256x256&sensor=false' />");     html.push("<p>Longitude: ", location.coords.longitude, "</p>");     html.push("<p>Latitude: ", location.coords.latitude, "</p>");     html.push("<p>Accuracy: ", location.coords.accuracy, " meters</p>");     message.innerHTML = html.join(""); } function errorHandler(error) {     alert('Attempt to get location failed: ' + error.message); } navigator.geolocation.getCurrentPosition(successHandler, errorHandler); </script> </head> <body> <div id="message">Location unknown</div> </body> </html> 
like image 168
SavoryBytes Avatar answered Oct 11 '22 07:10

SavoryBytes