2011-09-21 126 views
1

通過jsonparsing我再次解析所有的字符串值,我需要顯示的MapView緯度和經度..,我需要所有的座標存儲在一個單獨的數組 請人幫助我..提前 感謝從json解析獲取座標並在mapview中顯示?

+0

問題出在哪裏?如果你獲得了字符串值,那麼接下來呢? – Pratik

回答

1

我不確定你的parseString函數怎麼樣,我假設你可以得到2個字符串的lat和long值。作爲跟隨

 String coordinates[] = {"...","..."}; 
     double lat = Double.parseDouble(coordinates[0]); 
     double lng = Double.parseDouble(coordinates[1]); 

     p = new GeoPoint(
      (int) (lat * 1E6), 
      (int) (lon * 1E6)); 
     //mc is MapView object 
     mc.animateTo(p); 
     mc.setZoom(15); 

     mapView.invalidate(); 

要在地圖上顯示的剩餘部分都可以做,你需要創建在res位圖精確的疊加/文件夾

MarkerOverlay mark = new MarkerOverlay(); 
listOfOverlays = mapView.getOverlays(); 
     listOfOverlays.clear(); 
     listOfOverlays.add(mark); 
     mapView.invalidate(); 

類MapOverlay的可以被定義因此:

class MarkerOverlay extends com.google.android.maps.Overlay 
    { 
     //create a constructor here with p.x and p.y as parameters 

     @Override 
     public boolean draw(Canvas canvas, MapView mapView, 
     boolean shadow, long when) 
     { 
      super.draw(canvas, mapView, shadow);     

      Point screenPts = new Point(); 
      Bitmap bmp = BitmapFactory.decodeResource(
        getResources(), R.drawable.pushpin); 

     GeoPoint point = new GeoPoint(
           (int) (p.x * 1E6), 
           (int) (p.y * 1E6)); 

         mapView.getProjection().toPixels(point, screenPts); 
         canvas.drawBitmap(bmp, screenPts.x-16, screenPts.y-32, null); 
         canvas.drawText(parts[0],screenPts.x-16 , screenPts.y-40, new Paint()); 
        } 
       } 
      } 


      return true; 
     } 
    } 
+0

不需要這個** GeoPoint point = new GeoPoint((int)(px * 1E6),(int)(py * 1E6)); **您可以在mapView.getProjection()中直接使用GeoPoint的p對象).toPixels(p,screenPts); ** – Pratik