2015-07-06 34 views
1

我有代碼來顯示谷歌地圖的當前位置以及解析JSON數據的代碼。我想知道我在哪裏合併下面的代碼來繪製地圖中的json數據。在Android的谷歌地圖繪製JSON數據

JSONArray jsonarray = new JSONArray(response); 
for (int i = 0; i < jsonarray.length(); i++) { 
    JSONObject jsonobject = jsonarray.getJSONObject(i); 
    String value1 = jsonobject.getString("Key1"); 
    String value2 = jsonobject.getString("Key2"); 
} 

或者是有一些其他的方式來繪製JSON數據到谷歌地圖

回答

0

首先INITIALISE GoogleMap對象,你可以做任何你想要的地圖。

mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map_fragment_id)) 
         .getMap(); 
if(mMap != null) 
{ 
//here play with mMap object however you want. 
} 

,或者,如果地圖對象已經初始化,那麼就驗證這兩個位置和JSON數據,那麼這樣做

+0

請建議我編輯@M D,以便我可以改進我的解決方案。 – atifali

0

我已經實現了同樣的事情太多

地圖代碼

gMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map_fragment_id)) 
        .getMap(); 
     if(gMap != null) 
     { 


       gMap.animateCamera(CameraUpdateFactory.newLatLngZoom(myPosition,10)); 
       final Marker myLocation=gMap.addMarker(new MarkerOptions().icon(BitmapDescriptorFactory.position(myPosition).title("Your Location").snippet(Shared.mTotalMembers[39]).snippet(Shared.DataOnMap)) 



     } 

您的JSON代碼

JSONArray jsonarray = new JSONArray(response); 
for (int i = 0; i < jsonarray.length(); i++) { 
    JSONObject jsonobject = jsonarray.getJSONObject(i); 
    String value1 = jsonobject.getString("Key1"); 
    String value2 = jsonobject.getString("Key2"); 
    } 
Shared.DataOnMap=value1+value2;