2012-01-09 10 views
-1

私は現在のGPS位置情報アプリケーションをsamsung spica 1.5でテストしていますが、私の現在の位置は表示されません。ここでAndroidの現在のGPS位置が正しくありません

は私のコードです:

public class MaptestActivity extends MapActivity implements LocationListener { 
    private MapView mapView = null; 
     private LocationManager lm = null; 
     private double lat = 0; 
     private double lng = 0; 
     private MapController mc = null; 
     private MyLocationOverlay myLocation = null; 
     private String current; 
     private PositionMarkersList positionMarkersList = null; 

     @Override 
     public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     mapView = (MapView) this.findViewById(R.id.mapView); 
     mapView.setBuiltInZoomControls(true); 

     lm = (LocationManager) this.getSystemService(LOCATION_SERVICE); 
     lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10000, 0, this); 
     lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 10000, 0, this); 

     mc = mapView.getController(); 
     mc.setZoom(15); 





     myLocation = new MyLocationOverlay(getApplicationContext(), mapView); 
     myLocation.runOnFirstFix(new Runnable() {  
      public void run() { 
      mc.animateTo(myLocation.getMyLocation()); 
      mc.setZoom(17); 


      } 

     }); 

     mapView.getOverlays().add(myLocation); 
     GeoPoint pp=myLocation.getMyLocation(); 

     //addPosition(pp); 
     if (myLocation.isMyLocationEnabled()!=false) 
     { 
      GeoPoint p =myLocation.getMyLocation(); 
      lat= p.getLatitudeE6(); 
      lng= p.getLongitudeE6(); 
      Toast.makeText(getBaseContext(), 
        "geolocalisation activÈ lat: "+lat+ " long: " +lng, 
        Toast.LENGTH_SHORT).show(); 
     } 
     else 
     { 

      Toast.makeText(getBaseContext(), 
        "geolocalisation desactivÈe" , 
        Toast.LENGTH_SHORT).show(); 
     } 



     } 

     @Override 
     protected void onResume() { 
     super.onResume(); 
     myLocation.enableMyLocation(); 
     myLocation.enableCompass(); 
     } 

     @Override 
     protected boolean isRouteDisplayed() { 
     return false; 
     } 

     @Override 
     public boolean onKeyDown(int keyCode, KeyEvent event) { 
     if (keyCode == KeyEvent.KEYCODE_S) { 
      mapView.setSatellite(!mapView.isSatellite()); 
      return true; 
     } 
     return super.onKeyDown(keyCode, event); 
     } 

     public void onLocationChanged(Location location) { 
     lat = location.getLatitude(); 
     lng = location.getLongitude(); 
     Toast.makeText(
      getBaseContext(), 
      "Location change to : Latitude = " + lat + " Longitude = " 
       + lng, Toast.LENGTH_SHORT).show(); 
     GeoPoint p = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6)); 
     mc.animateTo(p); 
     mc.setCenter(p); 
     } 

     public void onProviderDisabled(String provider) { 
     } 

     public void onProviderEnabled(String provider) { 
     } 

     public void onStatusChanged(String provider, int status, Bundle extras) { 
     } 


//ajout d'une position 

     private void addPosition(GeoPoint geoPoint) { 
      OverlayItem overlayitem = new OverlayItem(geoPoint, current, current); 
      positionMarkersList.addMarker(overlayitem); 
     } 

} 

誰もがこのことについてどんな考えをしてください持っていますか?

実行をクリックしてアプリケーションをテストすると、テストする手段(仮想デバイス...)がありますが、 "!"電話の名前の近くに私は理由を知らない。

ありがとうございます!

答えて

1

Google APIを使用して仮想デバイスを作成する必要があります。

また、お使いのデバイスの場所が表示されている場所で、地図上の表示された場所が現在の場所からどれだけ離れているか知ることができますか?

+0

私はチュニジアにいると、それはフランス語で私の位置を示し!!!私は実際のデバイスでテストしています! sumsung galaxy spicaなぜそれは動作しません? –

+0

私がテストをしたときに私が持っているメッセージは、 "ジオローカリゼーションが非活性化"されています!!これは私の所在地と関連しているのでしょうか?チュニジアにいるかもしれません。 –

+0

あなたの携帯電話が現在の場所を取得していないため、あなたの端末は最後の既知の場所を返します。私の知識によると。デバイス上でGoogle Mapアプリケーションを実行し、アプリケーションのキャッシュされたすべてのデータを消去し、その後、現在の場所を取得しようとすると、現在の場所にそのアプリケーションをリロードします。 – rajpara

1

AndroidManifest.xmlに位置情報サービスの正しい権限を必ず含めてください。

GPS: ACCESS_FINE_LOCATION

WIFI: ACCESS_COARSE_LOCATION

すべての権限:can be found here

+0

はいこれらすべての許可が含まれています <使用許諾android:name = "android.permission.ACCESS_FINE_LOCATION"> \t \t \t \t

1
public Location getCurrentLocation() { 
    try { 

     LocationManager lm = (LocationManager)  getSystemService(Context.LOCATION_SERVICE); 
     // ---Get the status of GPS--- 
     boolean isGPS = lm.isProviderEnabled(LocationManager.GPS_PROVIDER); 

     // If GPS is not enable then it will be on 
     if (!isGPS) { 
      Intent intent = new Intent(
        "android.location.GPS_ENABLED_CHANGE"); 
      intent.putExtra("enabled", true); 
      sendBroadcast(intent); 
     } 

     Location location = lm 
       .getLastKnownLocation(LocationManager.GPS_PROVIDER); 
     if (location == null) { 
      location = lm 
        .getLastKnownLocation(LocationManager.NETWORK_PROVIDER); 
     } 
     return location; 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
    return null; 
} 
関連する問題