Reputation: 2344
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
Upvotes: 1
Views: 710
Reputation: 65371
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 (using watchPosition()
based on your comment). Capturing error
can 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/
var location = document.getElementById( 'location' );
var geo = window.navigator.geolocation.watchPosition( function ( position ) {
location.textContent = position.coords.latitude + ', ' + position.coords.longitude;
},
function ( error ) {
location.textContent = error.message;
}
);
//later if you want to cancel it
window.navigator.geolocation.clearWatch( geo );
<div id="location"></div>
Upvotes: 1