Massimo Scola
asked on
jQuery Mobile and OSM API Map - How do integrate the JSON reply
I am developing my first application with Apache Cordova and I need some assistanstance with the Open Street Map object. I am sending a request to the Open Street Map to get Lat/Lng of a location. I chose Manchester UK and I received the following JSON back:
In order to do this, I set to share a taxi (it's a taxi sharing app) first and then I click on Update Map.
This is the code for UpdateMap:
What do I need to do, in order to update the map?
index.html
index.js
www-cordova.zip
In order to do this, I set to share a taxi (it's a taxi sharing app) first and then I click on Update Map.
This is the code for UpdateMap:
function updateMap(address){
var onSuccess = function(position) {
var div = document.getElementById("map_canvas");
div.width = window.innerWidth - 20;
div.height = window.innerHeight * 0.8 - 40;
// change the zoomin level
map.setZoom(15);
if (address != undefined) {
// TODO 2(a) FR2.2
var endPoint = "https://nominatim.openstreetmap.org/search/" + address + "?format=json&countrycode=gb"
$.get(endPoint,function(e) {[embed=file 1418190][embed=file 1418191][embed=file 1418192]
var location = e;
map.setCenter({
lng: location.lng,
lat: location.lat
});
})
} else {
map.setCenter({
lng: position.coords.longitude,
lat: position.coords.latitude
});
}
};
var onError = function(error) {
alert(
"code: " + error.code + "\n" + "message: " + error.message + "\n"
);
};
navigator.geolocation.getCurrentPosition(onSuccess, onError, {
enableHighAccuracy: true
});
}
What do I need to do, in order to update the map?
index.html
index.js
www-cordova.zip
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Option 1: you can check: if a previous map element exists, than delete it and create a new
Open in new window
Option 2: if the map element exists, set it to null and create a newOpen in new window
Open in new window
Option 3: create a functionOpen in new window
Read more: LinkHope it helps,
Istvan