2012-04-03 5 views
3

들으 라 내가 project 내 프로젝트 나는 현재의 위도 - long.But을 보여, 내 현재 위치를 표시하고에서은 표시 할 수 없습니다

내가 표시 할 을 할 수 아니에요입니다 안드로이드에 내 현재 위치.

Thnx.

@Override 
public void onLocationChanged(Location location) { 
    // TODO Auto-generated method stub 
    Log.d(TAG, "onLocationChanged with location " + location.toString()); 
    // Displays lat, long, altitude and bearing 
    String text = String.format("Lat:\t %f\nLong:\t %f\nAlt:\t %f\nBearing:\t %f", location.getLatitude(), location.getLongitude(), location.getAltitude(), location.getBearing()); 
    this.locationText.setText(text); 

    try { 
     // This gets a list of addresses 
     List<Address> addresses = geocoder.getFromLocation(location.getLatitude(), 
       location.getLongitude(), 10); 
     for (Address address : addresses) { 
      this.locationText.append("\n" + "kaushik"); 
     } 

     // Convert latitude and longitude into int that the GeoPoint constructor can understand 
     int latitude = (int)(location.getLatitude() * 1000000); 
     int longitude = (int)(location.getLongitude() * 1000000); 

     point = new GeoPoint(latitude,longitude); 
     mapController.animateTo(point); 
     mapController.setZoom(16); 

     MapOverlay mapOverLay=new MapOverlay(); 
     mapOverLay.setPointToDraw(point); 
     List<Overlay> listOfOverlays=map.getOverlays(); 
     listOfOverlays.clear(); 
     listOfOverlays.add(mapOverLay); 

     map.invalidate(); 

    } catch (IOException e) { 
     Log.e("LocateMe", "Could not get Geocoder data", e); 
    } 
} 
+0

붙여 넣기를 사용하여 코드를 수정하여 변경할 수 있습니다. –

+0

@Agarwal 이미 프로젝트를 향상 시켰습니다. – kaushikSuman

+0

당신의 죄봉을 붙여 넣을 수 있다면 더 좋을 것 같습니다. –

답변

4
mapController.animateTo(point); 
mapController.setZoom(16); 
MapOverlay mapOverLay=new MapOverlay(); 
mapOverLay.setPointToDraw(point); 
List<Overlay> listOfOverlays=map.getOverlays(); 
listOfOverlays.clear(); 
listOfOverlays.add(mapOverLay); 

에 오버레이 아이콘을 추가 할 수 있습니다.

Drawable srcdrawable = getApplicationContext().getResources().getDrawable(R.drawable.pin_blue); 
CustomItemizedOverlay srcitemizedOverlay = new CustomItemizedOverlay(srcdrawable, getApplicationContext()); 
GeoPoint srcpoint = new GeoPoint((int)(Double.parseDouble(lat) * 1E6),(int)(Double.parseDouble(lng)* 1E6)); 
OverlayItem srcoverlayitem = new OverlayItem(srcpoint, "Hello!", "This is your Location."); 
srcitemizedOverlay.addOverlay(srcoverlayitem); 
mapView.getOverlays().clear(); 
mapView.getOverlays().add(srcitemizedOverlay); 
mapController.animateTo(srcpoint); 
mapController.setZoom(16); 

// 당신은지도에 둘 이상의 지점을 원하는 경우도 /*

Drawable srcdrawable = getApplicationContext().getResources().getDrawable(R.drawable.pin_blue); 
CustomItemizedOverlay srcitemizedOverlay = new CustomItemizedOverlay(srcdrawable, getApplicationContext()); 
forloop(setoflocations){ 
GeoPoint srcpoint = new GeoPoint((int)(Double.parseDouble(lat) * 1E6),(int)(Double.parseDouble(lng)* 1E6)); 
OverlayItem srcoverlayitem = new OverlayItem(srcpoint, "Hello!", "This is your Location."); 
if(srcitemizedOverlay!=null && mapController!=null){ 
srcitemizedOverlay.addOverlay(overlayitem); 
mapController.animateTo(point); 
animatePoint = point; 
} 
} 
mapView.getOverlays().clear(); 
mapView.getOverlays().add(srcitemizedOverlay); 

*/

는 CustomItemizedOverlay.java 클래스 아래

public class CustomItemizedOverlay extends ItemizedOverlay<OverlayItem> { 

    private final ArrayList<OverlayItem> mapOverlays = new ArrayList<OverlayItem>(); 

    private Context context; 

    public CustomItemizedOverlay(Drawable defaultMarker) { 
     super(boundCenterBottom(defaultMarker)); 
    } 

    public CustomItemizedOverlay(Drawable defaultMarker, Context context) { 
     this(defaultMarker); 
     this.context = context; 
    } 

    @Override 
    protected OverlayItem createItem(int i) { 
     return mapOverlays.get(i); 
    } 

    @Override 
    public int size() { 
     return mapOverlays.size(); 
    } 

    public void addOverlay(OverlayItem overlay) { 
     mapOverlays.add(overlay); 
     this.populate(); 
    } 

} 
+0

다른 질문을하면지도에서 lat-long을 사용하여 다른 4-5 위치를 어떻게 표시 할 수 있습니까? – kaushikSuman

+0

@Agarwal 이유 animatePoint = point; – kaushikSuman

+0

사용 여부에 따라 다릅니다. 그것을 사용하여 마지막 lat 및 long으로 이동합니다. 그게 다 .... 또 내가 천박하게 묘사 한 이유는 다른 사람에게 유용 할 것이다. –

0

는 GPS에서 페치 위도 긴 아래 라인 //와 위의 라인을 교체 현재 위치

myItemizedOverlay.addItem(point , "myPoint1", "myPoint1"); 
      m_mapView.getOverlays().add(myItemizedOverlay); 

mapController.animateTo(point); 
관련 문제