hi to all! and a request ;-)

3 views
Skip to first unread message

tzenobite

unread,
Dec 26, 2009, 10:36:27 AM12/26/09
to iPhoneWebDev
hi
i'm brand new of iphone programming, even if i was a hypercarder many
years ago and now i got a little knowledge bout javascript
so, now i'm playing with all this developer tools and i'm enjoying
myself so much

first, i'm trying dashcode tool to training myself with simple webapps
i got a simple question (i hope so): i need to get the device's speed
via gps
i know today it's possible to get position data into webapps:
http://developer.apple.com/mac/library/documentation/AppleApplications/Reference/WebKitDOMRef/Coordinates_idl/Classes/Coordinates/index.html
there seems to be all i have to know about it, but i can't figure out
how i will get the data in the webapp, or: i don't undertand what i
have to write in my javascript to get iphone's speed using these
classes
simply i need the js code to get speed...
anybody out there may help me?
thanks!

matteo (italia)

Remi Grumeau

unread,
Dec 26, 2009, 12:10:25 PM12/26/09
to iphone...@googlegroups.com
Hi, and welcome aboard :)

Take a look at

It uses the HTML5 built-in geolocalisation method, supported on iPhone Safari and desktop Firefox (since 3.5.x afair)

function getPosition(position)
{
	// PROMPT THE LONGITUDE
	alert(position.coords.latitude, position.coords.longitude));
	alert(position.coords.latitude, position.coords.latitude);
}

function errorCallback()
{  alert('error');	}

function myPosition()
{
	// GET GEOLOCALISATION INFOS FROM THE BROWSER
	navigator.geolocation.getCurrentPosition(getPosition, errorCallback, {maximumAge:600000});
}
Remi

Le 26 déc. 09 à 16:36, tzenobite a écrit :

--

You received this message because you are subscribed to the Google Groups "iPhoneWebDev" group.
To post to this group, send email to iphone...@googlegroups.com.
To unsubscribe from this group, send email to iphonewebdev...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/iphonewebdev?hl=en.



tzenobite

unread,
Dec 27, 2009, 5:27:25 AM12/27/09
to iPhoneWebDev
many thanks! i will try asap (now i'm in trouble with a 'if' loop)

Andrew Hedges

unread,
Dec 27, 2009, 2:45:59 PM12/27/09
to iPhoneWebDev
Here is a simple example page you can use as a starting point for
browser-based geolocation:

http://segdeha.com/w/geolocation.html

To track speed, you would need to track your location over time.
Easiest might be to set up a setInterval call to get the location
every few seconds and save it to an array. Something like the
following (untested):

var readings = [];
setTimeout(function () {
navigator.geolocation.getCurrentPosition(function(position) {
readings.push(position.coords);
});
}, 10000); // repeat every 10 seconds

Once you have your readings, here is a script that may be helpful for
finding distances based on Latitude/Longitude:

http://segdeha.com/e/haversine/

Good luck!

Remi Grumeau

unread,
Dec 27, 2009, 6:13:09 PM12/27/09
to iphone...@googlegroups.com
For info, here is the log i have using Firefox 3.5.x on MacOS X, wifi macbook.

• timestamp: 1261955498739
• coords: [xpconnect wrapped (nsISupports, nsIDOMGeoPositionCoords, nsIClassInfo)]
• contractID:
• classDescription: wifi geo location position object
• classID: null
• implementationLanguage: 2
• flags: 8
• SINGLETON: 1
• THREADSAFE: 2
• MAIN_THREAD_ONLY: 4
• DOM_OBJECT: 8
• PLUGIN_OBJECT: 16
• EAGER_CLASSINFO: 32
• CONTENT_NODE: 64
• RESERVED: 2147483648

Remi

Kilian

unread,
Dec 27, 2009, 10:31:26 PM12/27/09
to iphonewebdev
so high level code


--

-----------------------------

Regards By Killian

Tel : 13764839658 

Mail & Msn :   eh...@163.com


> wrote:
>> many thanks! i will try asap (now i'm in trouble with a 'if' loop)
>
>--
>
>You received this message because you are subscribed to the Google Groups "iPhoneWebDev" group.
>To post to this group, send email to iphone...@googlegroups.com.
>To unsubscribe from this group, send email to iphonewebdev...@googlegroups.com.
>For more options, visit this group at http://groups.google.com/group/iphonewebdev?hl=en.
>
>


Dylan Phillips

unread,
Jan 8, 2010, 11:40:56 AM1/8/10
to iPhoneWebDev
Andrew:

I just implemented this myself and found a bit of an issue.

Calls to getCurrentPosition() are highly inaccurate, if you have not
recently used GoogleMaps or are on a SkyHook Network Node. I found
this out, while taking the dog for a walk in the park. Droid was Spot
on, but the iPhone stayed at the house or the cell tower.

This morning I discovered that watchPosition() worked like a charm.
You may want to go with that.

-Dylan

Reply all
Reply to author
Forward
0 new messages