PDA

View Full Version : Ext.Map with geolocation problem



NitrOuS
2 Dec 2010, 5:28 AM
What I want to do is to have a map to show the user's current location. And I have the following problem while testing as part whole application. When I want to show the map I can't get the user's location. Here is the code:



var currentLocationMap = new Ext.Map({
getLocation: true,
fullscreen: true
});

MyNameSpace.NearUserLocationMap = new Ext.Panel({
items: [currentLocationMap]
});

While testing it in my chrome browser I don't even get the warning that the localhost wants to know my location.What am I doing wrong?

kevinv1990
2 Dec 2010, 5:31 AM
Heey,

here you go, put this in the JS file:


geo = new Ext.util.GeoLocation({
accuracy: 1,
autoUpdate: true,
listeners: {
locationupdate: function (geo) {
currentLat = geo.latitude;
currentLng = geo.longitude;
currentLocation = new google.maps.LatLng(geo.latitude, geo.longitude);
},
locationerror: function (geo, bTimeout, bPermissionDenied, bLocationUnavailable, message) {
if(bTimeout){
alert('Helaas kunnen we uw locatie niet bepalen');
}
else{
alert('Helaas kunnen we uw locatie niet bepalen');
}
}
}
});
geo.updateLocation();

kevinv1990
2 Dec 2010, 5:32 AM
Here you go:


geo = new Ext.util.GeoLocation({
accuracy: 1,
autoUpdate: true,
listeners: {
locationupdate: function (geo) {
currentLat = geo.latitude;
currentLng = geo.longitude;
currentLocation = new google.maps.LatLng(geo.latitude, geo.longitude);
},
locationerror: function (geo, bTimeout, bPermissionDenied, bLocationUnavailable, message) {
if(bTimeout){
alert('Helaas kunnen we uw locatie niet bepalen');
}
else{
alert('Helaas kunnen we uw locatie niet bepalen');
}
}
}
});
geo.updateLocation();

kevinv1990
2 Dec 2010, 6:08 AM
You can retrieve current location of the user by :


// Current location
geo = new Ext.util.GeoLocation({
accuracy: 1,
autoUpdate: true,
listeners: {
locationupdate: function (geo) {
currentLat = geo.latitude;
currentLng = geo.longitude;
currentLocation = new google.maps.LatLng(geo.latitude, geo.longitude);
},
locationerror: function (geo, bTimeout, bPermissionDenied, bLocationUnavailable, message) {
if(bTimeout){
alert('Helaas kunnen we uw locatie niet bepalen');
}
else{
alert('Helaas kunnen we uw locatie niet bepalen');
}
}
}
});
geo.updateLocation();

currentLocation will be filled with the lat and lng ;) and can be used for the position of a marker, or can be used to zoom the map on.

NitrOuS
3 Dec 2010, 2:20 AM
I have also tried to put the code from map example in my application and none worked. Any ideas?

NitrOuS
3 Dec 2010, 10:57 AM
@Kevin: Firstly I'd like to thank you for your answer. I tried to do what you said but I couldn't get it to work. I don't currently have the code snippet to show exactly what I'm doing, but I have one more clue. In neither desktop nor iPhone,where I'm currently testing my apps, I get the notice that the site wants to know where I am. Moreover as I said in a previous post I took the whole map example and put it on my project and I just changed the main Panel defining it as part of my application namespace and just didn't work, although the example itself worked fine. How is that possible? Do you have any idea? Thanks in advance for your time.

jep
19 Jan 2011, 1:04 PM
FYI, there are some bugs in Ext.Map that cause it to not work. See here:

http://www.sencha.com/forum/showthread.php?119688-OPEN-695-Default-Ext.Map-GeoLocation-object-is-initialized-with-an-invalid-option

Here's a thread where I come up with an example of how to get it to work:
http://www.sencha.com/forum/showthread.php?121673-Get-current-location-on-map