我正在創建一個應用程序,我必須獲取用戶的經度和緯度並標記他的位置。我的應用出現錯誤「不幸地圖已停止」。我GOOGLE了很多,但無法找到解決方案。這裏是我的代碼和我的日誌貓。如何獲取Android應用程序的經度緯度
public class MapView extends Activity {
private LocationManager locationManager;
private String best;
double myLocationLatitude;
double myLocationLongitude;
Location loc = locationManager.getLastKnownLocation(best);
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map_layout);
locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
// additionally (you have to implement LocationListener)
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0.0f, new android.location.LocationListener()
{
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
Log.d("a","onLocationChanged: lat=" +location.getLatitude());
Log.d("a","onLocationChanged: lat=" +location.getLongitude());
}
});
locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
GoogleMap mMap = null;
mMap.addMarker(new MarkerOptions().draggable(true)
.position(new LatLng(loc.getLatitude(),loc.getLongitude()))
.title("YOUR LOCATION"));
LOG CAT:
1月3日至29日:37:37.167:d/ActivityThread(2521):installProvider: context=[email protected]=android.app.IActivityManager $ ContentProviderHolder @ 41fb9070noisy = truenoReleaseNeeded = falsestable = false 03-29 01:37:37.364:D/dalvikvm(2521):GC_FOR_ALLOC已釋放870K,13% 免費6526K/7424K,暫停110ms,共110ms 03-29 01:37 :37.365: D/ActivityThread(2521):installProvider: [email protected]=andr [email protected]=truenoReleaseNeeded=falsestable=false 03-29 01:37:37.637:E/linker(2521):load_library(linker.cpp:757): library 「/ data/data/「com.google.android.gms/files/libAppDataSearchExt_armeabi_v7a.so」 not found 03-29 01:37:37.642:D/ActivityThread(2521):installProvider: [email protected]=android.app。 IActivityManager $ ContentProviderHolder @ 41f7ffd8noisy = truenoReleaseNeeded = falsestable = false 03-29 01:37:37.833:D/ActivityThread(2521):installProvider: context = android.app.ContextImpl @ 41e4f100holder = android.app.IActivityManager $ ContentProviderHolder @ 41ea8d40noisy = truenoReleaseNeeded = falsestable = false 03-29 01:37:38.324:D/ActivityThread(2521):installProvider: context = android.app.ContextImpl @ 41e4f100holder = android.app.IActivityManager $ ContentProviderHolder @ 41f19948noisy = truenoReleaseNeeded = falsestable = false 03-29 01:37:38.645:D/ActivityThread(2521):installProvider: context = android。 app.ContextImpl @ 41e4f100holder = android.app.IActivityManager $ ContentProviderHolder @ 41fa1000noisy = truenoReleaseNeeded = falsestable = false 03-29 01:37:38.658:D/ActivityThread(2521):installProvider: [email protected] [email protected]y=truenoReleaseNeeded=falsestable=false 03-29 01:37:38.668:I/Icing(2521):內部初始化完成:存儲狀態0 03-29 01:37:38.725: D/ActivityThread(2521):installProvider: [email protected]我的/結冰(2521):初始化完成03-29 01:37:38.879: W/asset(2521):AssetManager - > addDefaultAssets CIP路徑不存在! 一月3日至29日:37:40.148:I/dalvikvm(2521):找不到方法 android.app.admin.DevicePolicyManager.isDeviceOwnerApp,從方法 com.google.android.gms.init.InitializeIntentService.onHandleIntent引用 03-29 01:37:40.148:W/dalvikvm(2521):VFY:無法解析虛擬 方法1697:Landroid/app/admin/DevicePolicyManager; .isDeviceOwnerApp (Ljava/lang/String;)Z 03-29 01:37:40.148:d/dalvikvm(2521):VFY:從 com.google.android.googlequicksearchbox 03 索引38E683E5680B78374039C38CC697D19B079F6A63: 更換操作碼0x6e在0x00e0 1月3日至29日:37:40.903:I /冰(2521) -29 01:37:41.108: D/ActivityThread(2521):installProvider: 上下文= android.app.ContextImpl @ 41e4f100holder = android.app.IActivityManager $ ContentProviderHolder @ 420511f0noisy = truenoReleaseNeeded = falsestable =假 一月3日至29日:37:41.505:d/ActivityThread(2521):installProvider: 上下文=機器人。應用程序。ContextImpl @ 41e4f100holder = android.app.IActivityManager $ ContentProviderHolder @ 420542a0noisy = truenoReleaseNeeded = falsestable = false 03-29 01:37:41.520:D/ActivityThread(2521):installProvider: [email protected]=android .app.IActivityManager $ ContentProviderHolder @ 42055cb8noisy = truenoReleaseNeeded = falsestable =假 1月3日至29日:37:41.534:d/ActivityThread(2521):installProvider: [email protected]=android.app.IActivityManager$ ContentProviderHolder @ 42058ce8noisy = truenoReleaseNeeded = falsestable = false 03-29 01:37:41.546:D/ActivityThread(2521):installProvider: context = android.app.ContextImpl @ 41e4f100holder = android.app.IActivityManager $ ContentProviderHolder @ 4205a700noisy = truenoReleaseNeeded = falsestable = false 03-29 01:37:4 1.554:I /冰(2521):索引完成 38E683E5680B78374039C38CC697D19B079F6A63一月3日至29日:37:44.889: d/IPCThreadState(2521):DN#5] BR_CLEAR_DEATH_NOTIFICATION_DONE 餅乾0x41263ee8
需要初始化的LocationManager。 – dharms
我試過了,但錯誤沒有解決。 –
請用你試過的東西更新你的問題。在初始化之前確保你沒有使用'locationManager'。 ('Location loc = locationManager.getLastKnownLocation(best);'是一個很好的例子) – dharms