3.0 OS and Location

September 15, 2009 · Print This Article

There is a new spec (http://dev.w3.org/geo/api/spec-source.html ) to be aware of and incorporate into your code if you are going to use the GPS on the new iPhone 3.0 OS.  Here is how to do it.

Note the difference is the “p.coords.latitude” versus “p.latitude” and how to detect the version of the OS:

<?xml version=”1.0″ encoding=”UTF-8″?>

<!DOCTYPE html

PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”

http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“>

<html xmlns=”http://www.w3.org/1999/xhtml” xml:lang=”en” lang=”en”>

<head>

<script type=”text/javascript” src=”http://apps.pointabout.com/static/mobile_interface/2.0.0/js/basic_interface.js“></script>

<script type=”text/javascript”>

function init_device() {

alert(Device.version);

document.getElementById(’mydiv’).innerHTML=”Hello world”;

}

var getLocation = function() {

var suc = function(p){

userlat = document.getElementById(’userlat’);

userlng = document.getElementById(’userlon’);

if( Device.version == “3.0″ ) {

userlat.innerHTML = p.coords.latitude;

userlng.innerHTML = p.coords.longitude;

} else {

userlat.innerHTML = p.latitude;

userlng.innerHTML = p.longitude;

}

};

var fail = function(){};

navigator.geolocation.getCurrentPosition(suc,fail);

}

</script>

</head>

<body>

<div id=’mydiv’>Springboard sandbox</div>

<ul>

<li><a href=”#readgeo” onclick=”getLocation();”>Location</a></li>

</ul>

<div id=’userlat’>location…</div>

<div id=’userlon’>location…</div>

</body>

</html>

Comments

Got something to say?