1

I am working in a project that uses Cordova geolocation plugin that will search for users around you. However, I cannot get the geolocation from the simulator, nor on the device. Before I use to get the coordinates but very unstable. After some code to fix the bug, I am now getting an error most of the time. I tried this for a week with no success.
Any input, or advice?

The JavaScript file:

/***********Geolocation GEOLOCATION*************/        


// Wait for device API libraries to load

document.addEventListener("deviceready", onDeviceReady, false);

// device APIs are available
//
function onDeviceReady() {

    var options = {maximumAge: 0, timeout: 15000, enableHighAccuracy:true};

    navigator.geolocation.getCurrentPosition(onSuccess, onError, options);
}


// onSuccess Geolocation
//
var onSuccess = function(position) {
    document.getElementById('userLat').value = position.coords.latitude;
    document.getElementById('userLong').value = position.coords.longitude;

    document.getElementById('extraUserLat').value = position.coords.latitude;
    document.getElementById('extraUserLong').value = position.coords.longitude;
    //document.getElementById('extraUserTest').innerHTML = position.coords.longitude;


};

// onError Callback receives a PositionError object
//
function onError(error) {
    alert('There Was An Error Getting Your Location. Please Check That You Have WiFi and Location Services Enabled. '    + error.code    + '\n' +
          'message: ' + error.message + '\n');


}

The XML file:

<js-module src="www/Coordinates.js" name="Coordinates">
        <clobbers target="Coordinates" />
    </js-module>

    <js-module src="www/PositionError.js" name="PositionError">
        <clobbers target="PositionError" />
    </js-module>

    <js-module src="www/Position.js" name="Position">
        <clobbers target="Position" />
    </js-module>

    <js-module src="www/geolocation.js" name="geolocation">
        <clobbers target="navigator.geolocation" />
    </js-module>

    <config-file target="config.xml" parent="/*">
        <feature name="Geolocation">
            <param name="ios-package" value="CDVLocation"/>
            <feature name="http://api.phonegap.com/1.0/geolocation" />
        </feature>
    </config-file>
    <header-file src="ios/CDVLocation.h" />
    <source-file src="ios/CDVLocation.m" />
    <framework src="CoreLocation.framework" />

    <config-file target="*-Info.plist" parent="NSLocationWhenInUseUsageDescription">
        <string></string>
    </config-file>

HTML:

user3356128
  • 67
  • 2
  • 13

0 Answers0