2011-12-10 44 views
3

我想查找當前位置並在該位置上製作標記。 PLZ告訴我如何找到當前位置並在該位置製作標記。

如果任何例子是有那麼請告訴我..

像在推進這一

enter image description here

謝謝...

+0

請添加什麼,你有沒有嘗試到現在? – PravinCG

+0

http://developer.android.com/guide/tutorials/views/hello-mapview.html看到這個你可能會想法 – Abhi

回答

1

爲找到當前位置使用全球定位系統。你可以得到更多的例子,併爲標記看到這個鏈接。 https://github.com/jgilfelt/android-mapviewballoons

+0

告訴我你的電子郵件ID請... – Patel

+0

使用你的鏈接我必須通過經緯度手動 但我希望通過自動。? – Patel

+0

是的,使用GPS_PROVIDER你可以獲得經度和緯度。你可以嘗試修改代碼 –

0

我們這裏有幾個簡單的步驟

class MapOverlay extends com.google.android.maps.Overlay 
    { 
     @Override 
     public boolean draw(Canvas canvas, MapView mapView, 
     boolean shadow, long when) 
     { 
      super.draw(canvas, mapView, shadow);     

      //---translate the GeoPoint to screen pixels--- 
      Point screenPts = new Point(); 
      mapView.getProjection().toPixels(p, screenPts); 

      //---add the marker--- 
      Bitmap bmp = BitmapFactory.decodeResource(
       getResources(), R.drawable.pin);    
      canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null);   
      return true; 
     } 
    } 

ABV代碼後,打電話給你的標記

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    mapView = (MapView) findViewById(R.id.mapView); 

    Geocoder geocoder = new Geocoder(this, Locale.getDefault()); 
    List<Address> addresses = null; 
    try { 
     addresses = geocoder.getFromLocationName(getIntent().getStringExtra("address"), 1); 
    } catch (IOException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 
    Address address = addresses.get(0); 
    double lng = address.getLongitude(); 
    double lat = address.getLatitude(); 



    p = new GeoPoint(
     (int) (lat * 1E6), 
     (int) (lng * 1E6)); 

    mc.animateTo(p); 
    mc.setZoom(17); 

    //---Add a location marker--- 
    MapOverlay mapOverlay = new MapOverlay(); 
    List<Overlay> listOfOverlays = mapView.getOverlays(); 
    listOfOverlays.clear(); 
    listOfOverlays.add(mapOverlay);   

    mapView.invalidate(); 
    mapView.invalidate(); 
} 

希望我已經清除你一些什麼。保持微笑:)