Here is the problem I have: I need to build an app that geolocates you and fetch the weather for your area. I have a problem with the geolocation that I can't solve.
I put everything in a "Place" object that I build with a constructor (I put here only the part that builds the URL of the Google map that will be displayed):
function Place() {
this.mapURL = "#";
this.setMapURL = function(location) {
var lat = location.coords.latitude;
var long = location.coords.longitude;
this.mapURL = 'https://maps.googleapis.com/maps/api/staticmap?center=' + lat + ',' + long + '&zoom=12&size=300x300&sensor=false';
};
this.displayMap = function() {
var map = new Image();
map.src = this.mapURL;
mapContainer.html('Retrieving your position...');
mapContainer.html(map);
};
}
In the main code, I create a Place object and then call "getCurrentPosition" on this object, which itself calls "setMapURL":
var myPos = new Place();
navigator.geolocation.getCurrentPosition(myPos.setMapURL, error, geoOptions);
NB: the "error" and "geoOptions" are defined elsewhere.
The problem I have is that the property "mapURL" of the "myPos" object doesn't get updated. Its value stays "#".
There might be something I miss here but I really can't find what it is.
If you have any idea, let me know!
Thanks!!