I am very new to JAVA programming, but I am in a big trouble and this will depend on my job. Anyway. Okay so I have this json here:
{
"GetPOIByTypeResult": [
{
"Address": {
"City": "Bucuresti",
"ID": 1,
"Number": 3,
"Street": "Otopeni"
},
"ID": 1,
"IsSpecial": true,
"Latitude": 44.542869567871094,
"Logo": "6fb43083ee663364ef6771293653e56b.jpg",
"Longitude": 26.06893539428711,
"Name": "Spitalul Judetean",
"Phone": "085228291",
"Remark": "Normal Hospital",
"Schedule": "Monday to Friday",
"Specialities": [
{
"ID": 1,
"Name": "Stomatologie"
},
{
"ID": 2,
"Name": "Radiologie"
},
{
"ID": 3,
"Name": "Cardiologie"
},
{
"ID": 4,
"Name": "Ginecologie"
},
{
"ID": 5,
"Name": "Pediatrie"
},
{
"ID": 6,
"Name": "Patologie"
},
{
"ID": 7,
"Name": "Oncologie"
},
{
"ID": 8,
"Name": "Macelarie"
},
{
"ID": 9,
"Name": "Oftalmologie"
},
{
"ID": 10,
"Name": "Ghipsologie"
}
],
"Type": "Hospital"
},
I need to get the latitude and longitude from the JSON and show the location on google maps in my application. I have this little code snippet over here, it works great with local coordinates, like entering my own numbers, but I want it to get it from JSON.
drawable = getResources().getDrawable(R.drawable.marker);
itemizedOverlay = new CustomItemizedOverlay<CustomOverlayItem>(drawable, mapView);
GeoPoint point2 = new GeoPoint((int)(44.55332946777344*1E6),(int)(26.07666015625*1E6));
CustomOverlayItem overlayItem2 = new CustomOverlayItem(point2, "Bucuresti Spital 2",
"(Spitalul 2)",
"http://ia.media-imdb.com/images/M/MV5BMzk2OTg4MTk1NF5BMl5BanBnXkFtZTcwNjExNTgzNA@@._V1._SX40_CR0,0,40,54_.jpg");
itemizedOverlay.addOverlay(overlayItem2);</code>
I have a JSONparser set up,I just don't know how to make the mapcontroller to animateTo the point where my coordinates are,so I would like to get some help with this :-S
EDIT: This is how I resolved my problem, maybe it will help some1 else too.
drawable = getResources().getDrawable(R.drawable.marker);
itemizedOverlay = new CustomItemizedOverlay<CustomOverlayItem>(
drawable, mapView); //showing marker on the map
public void showHospitalList(ArrayList<Hospitals> hospitals) {
for (int i = 0; i < hospitals.size(); i++) {
Hospitals hospital = hospitals.get(i);
CustomOverlayItem temp1 = toOverlay(hospital);
itemizedOverlay.addOverlay(temp1);
}
mapOverlays.add(itemizedOverlay); //this is to get the list in the activity
}
public CustomOverlayItem toOverlay(Hospitals hospitals) {
GeoPoint point = new GeoPoint((int) (hospitals.Latitude * 1E6),
(int) (hospitals.Longitude * 1E6));
CustomOverlayItem temp = new CustomOverlayItem(
point, hospitals.Name, hospitals.Phone, hospitals.Type);
return temp;
// used the hospitals object to define the cordinates and then multiplied by 1E6 to make it compatible(from double to int)
// Last line defines the balloon pop-up and what to show(everything is from json).
}
Thank you for helping