I have an HTML app, not a native app. It’s like a website, and I access a url with my mobile device, like a website. And geolocation doesn’t work. It’s a Phonegap app. I have: index.html, cordova-1.9.0.js, and two .js that contain the functions.
I posted my problem of not obtaining the coordinates on the Phonegap group of Google, and Simon Mac Donald answered me that I was doing it all wrong, but he was busy and told me that he would answer me later…
Now, I visit my post, but no updates. Could anyone explain to me a little?
Thanks very much, Daniel
PhoneGap is for native apps. You write code in HTML, Javascript and CSS, add a link to the cordova/phonegap.js file and then compile it to one of the supported platforms (iOS, Android, Winphone, etc). The end result is a native application.
You cannot use PhoneGap or any of its functionality in a web app.
Now, location services can be used in a web app because it is provided by all modern browsers. The object you need is
window.navigator.geolocation. Here’s a sample of how to use it (usingwatchPosition()based on your comment). Capturingerrorcan help you track down why it’s not working for you.Demo (code): http://jsfiddle.net/ThinkingStiff/UZwdv/
Demo (open on your phone): http://jsfiddle.net/ThinkingStiff/UZwdv/show/
Script
HTML