我對JAVA編程非常陌生,但我遇到了很大的麻煩,這取決於我的工作。無論如何。 好了,所以我有這個JSON這裏:從JSON獲取座標並在Android上的Google地圖上移動到他們
{
"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"
},
我需要從JSON的緯度和經度,並顯示在我的應用程序在谷歌地圖上的位置。 我在這裏有這個小小的代碼片段,它可以與本地座標很好地工作,就像輸入我自己的數字一樣,但我希望它能從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/MV5BM[email protected]@._V1._SX40_CR0,0,40,54_.jpg");
itemizedOverlay.addOverlay(overlayItem2);</code>
我有一個JSONparser成立,我只是不知道如何使mapcontroller到animateTo在我的座標點,所以我希望得到一些幫助,這:-S
編輯:這是我如何解決我的問題,也許它也會幫助其他人。
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).
}
謝謝你幫
你似乎在這裏問兩個問題。 1)解析JSON以獲得緯度/經度。 2)動畫到該位置。儘量不要混淆,以便更好地理解。您解析JSON並將lat/long存儲在對象中,然後在動畫地圖時使用該對象。祝你好運:) – RobGThai 2012-07-23 09:05:53
我是新來的Android編程,你能給我一個例子如何將緯度/長度存儲在一個對象,並在上面的代碼中使用它? – SethPDA 2012-07-23 09:13:35