乾杯、私はAndroid経由で現在のGPS位置を取得しようとしています。私はthis TutorialとVogellas articleの順に続きました。それは動作していません。 LocationManager.NETWORK_PROVIDERを使用する場合、私はどこにいても、常に51の緯度と9の経度を取得しています。 LocationManager.GPS_PROVIDERを使用すると、何も得られません。Android GPSの場所を取得する方法
GMapsを使用するとすべてが機能しますが、理由はわかりません。 GMapsのような現在のGPS位置を取得するにはどうしたらいいですか?ここで
は私のコードです:
package com.example.gpslocation;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.Menu;
public class GPS_Location extends Activity implements LocationListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gps__location);
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.gps__location, menu);
return true;
}
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
int latitude = (int) (location.getLatitude());
int longitude = (int) (location.getLongitude());
Log.i("Geo_Location", "Latitude: " + latitude + ", Longitude: " + longitude);
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
}
高レベルとGPSの位置を取得する簡単な方法のために、あなたはこのライブラリを使用することがあります。https://github.com/delight-im/Android-SimpleLocation – caw
http:// stackoverflowを確認してください。com/questions/1513485/how-do-i-get-the-current-gps-location-programmatically-in-android/38897436#38897436 –