2011-08-24 55 views
0

我有一個Android應用程序,需要一個陣列從一個網站我如何從谷歌一個JSON陣列發佈多個標記映射

{「d」:[{「緯度」 - 1.0「東經」: -1.0,「time」:「07:14 PM 01/18/2038」,「most_recent」:「1」,「user_id」:「4e3f2c6659f25a0f8400000b」},{「緯度」: - 1.0,「經度」: - 1.0 ,「時間」:「07:14 PM 01/18/2038」,「most_recent」:「0」,「user_id」:「4e3f2c6659f25a0f8400000b」},{「緯度」: - 1.0,「經度」: - 1.0,時間「:」07:14 PM 01/18/2038「,」most_recent「:」0「,」user_id「:」4e3f2c6659f25a0f8400000b「},{」緯度「:34.0608,」經度「: - 118.454,​​」時間「: 「07:14 PM 01/18/2038」,「most_recent」:「1」,「user_id」:「4e3da65e59f25a3956000005」},{「緯度」:34.0608,「經度」: - 118.454,​​「時間」 14:00 01/18/2038「,」most_recent「:」0「,」user_id「:」4e3da65e59f25a3956000005「},{」緯度「:34.0608,」經度「: - 118.454,​​」時間「:」07:1 4 PM 01/18/2038「,」most_recent「:」0「,」user_id「:」4e3da65e59f25a3956000005「}]}

您可以看到每個項目都有一個緯度和經度組件以及一個ID。

如何修改這個程序來顯示一個綠色針R.drawable.greenpin或「user_ID的」藍針R.drawable.bluepin:「4e3f2c6659f25a0f8400000b」或「USER_ID」:數組中的「4e3da65e59f25a3956000005」爲每個項目的(應該是三藍色銷,並在這些地區三個綠色引腳)

public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) 
{ 
super.draw(canvas,mapView,shadow); 
Point screenPts=new Point(); 
mapView.getProjection().toPixels(p,screenPts); 
Bitmap bmp=BitmapFactory.decodeResource(getResources(),R.drawable.greenpin); 
canvas.drawBitmap(bmp,screenPts.x,screenPts.y-50,null); 
return true; 
} 
} 

//to add the location marker 
MapOverlay mapOverlay=new MapOverlay(); 
List<Overlay> listOfOVerlays=mapView.getOverlays(); 
listOfOverlays.clear(); 
listOfOverlays.add(mapOverlay); 

,我有混淆我有點,因爲它提請根據屏幕點的點的方法。我寧願通過插入陣列的經度和緯度來添加這些點。

回答

0

我不明白你想要什麼,但在我的情況下,這段代碼爲我工作,把標記放在合適的緯度,長地址。

myPoint = new GeoPoint(((int) LATITUDE_Add) * 1E6),(int)LONGITUDE_Add) * 1E6)); 
drawable = getResources().getDrawable(R.drawable.marker_blue); 
itemizedoverlay = new MapOverLay(drawable, MapPage.this, mapview); 
OverlayItem overlayitem = new OverlayItem(myPoint, address, ""); 

itemizedoverlay.addOverlay(overlayitem); 
mapOverlays.add(itemizedoverlay); 
mapview.getController().animateTo(myPoint); 

Thnx。