2011-02-03 5 views
2

hé les gens, j'ai encore besoin de votre aide Eh bien, j'ai construire l'application de la carte et fonctionne parfaitement, maintenant je veux voir mon emplacement actuel dans cette carte. Comment s'y prendre? plz suggèrentCoordonnées Gps sur google map

Répondre

2

Il existe différentes façons de le faire,

U besoin d'ajouter un écouteur d'emplacement. Il existe deux types, l'un utilise le GPS lui-même (ce ne fonctionne pas à l'intérieur), en utilisant le réseau.

private LocationManager locationManager; 
public LocationListener locationListener; 
public LocationListener locationListener2; 

locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); 
      locationListener = new MyLocationListener(); 
      locationListener2 = new MyLocationListener();    
      locationManager.requestLocationUpdates(locationManager.GPS_PROVIDER, 0, 0, locationListener); 
      locationManager.requestLocationUpdates(locationManager.NETWORK_PROVIDER, 0, 0, locationListener2); 



//Location lister 
private class MyLocationListener implements LocationListener { 
    public void onLocationChanged(Location loc) { 

     mlongti = loc.getLongitude(); 
     mlatiti = loc.getLatitude(); 
     GeoPoint userLoc = new GeoPoint((int) (mlatiti * 1E6), (int) (mlongti * 1E6)); 
     LItemizedOverlay itemizedoverlay = new LItemizedOverlay(selfImage,getParent(), "",userLoc,display); 

     try {   
      OverlayItem overlayitem = new OverlayItem(userLoc, "", ""); 
      itemizedoverlay.addOverlay(overlayitem); 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 

     List<Overlay> listOfOverlays = map.getOverlays(); 
     listOfOverlays.add(itemizedoverlay); 
     MapController mc = map.getController();   
     mc.animateTo(userLoc); 
     mc.setZoom(10); 
     map.invalidate();  
     if(locationManager!=null && locationListener2 != null){ 
      locationManager.removeUpdates(locationListener); 
      locationManager.removeUpdates(locationListener2); 
      locationManager= null; 
     } 
    } 

    public void onProviderDisabled(String provider) { 
     // TODO Auto-generated method stub 
    } 
    public void onProviderEnabled(String provider) { 
     // TODO Auto-generated method stub 
    } 
    public void onStatusChanged(String provider, int status, Bundle extras) { 
     // TODO Auto-generated method stub 
    } 
} 
Questions connexes