Hi,
In my Sencha app 2.1 i use the current location, so it work great on browser but when i package my application with Phonegap 2.2 for android devices, it doesn't work . Is there any method to know the current location whitout specifing (navigator) or using : useCurrentLocation: true" then "this.getMap()._geo.getLatitude();"
Code:
onDistTap: function () {
var liste = this.getPlaces();
var store = liste.getStore();
store.each(function (record) {
var lat = record.data.lat;
var lng = record.data.lng;
navigator.geolocation.getCurrentPosition(function (position) {
// Distance calcule
if (typeof(Number.prototype.toRad) === "undefined") {
Number.prototype.toRad = function() {
return this * Math.PI / 180;
}
}
var lat1 = lat ;
var lon1 = lng ;
var lat2 = position.coords.latitude;
var lon2 = position.coords.longitude;
var R = 6371; // km
var dLat = (lat2-lat1).toRad();
var dLon = (lon2-lon1).toRad();
var lat1 = lat1.toRad();
var lat2 = lat2.toRad();
var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var d = R * c;
console.log('Distance (km)');
console.log(d);
record.data.distance = d; liste.setData(record.data);
});
});
//store.setData(liste);
store.sync();
store.sort('distance', 'ASC');
}
Thanks in advance