2011-02-03 8 views
2

に人々を座標、私はよく私は今、私はそのマップで自分の現在位置を表示したい、地図アプリケーションを構築しており、完全に実行されている もう一度お願いします。それについて移動する方法? plzが提案するGPSはちょっとグーグルマップ

答えて

2

さまざまな方法があります。

Uロケーションリスナーを追加する必要があります。 1は、ネットワークを使用して、(これは文句を言わない屋内で働く)GPS自体を使用している2種類があります。

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 
    } 
} 
関連する問題