gpt4 book ai didi

android获取当前位置

转载 作者:行者123 更新时间:2023-11-29 22:14:26 26 4
gpt4 key购买 nike

我正在测试一个使用 sumsung galaxy spica 获取当前位置的应用程序,它向我显示了与我的位置不同的另一个位置,并且与 AVD 中显示的位置不同!! gps 已激活,但我不知道问题到底出在哪里。这是我的代码

import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.KeyEvent;
import android.widget.Toast;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.MyLocationOverlay;

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;

@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);




myLocation = new MyLocationOverlay(getApplicationContext(), mapView);
myLocation.runOnFirstFix(new Runnable() {
public void run() {
mc.animateTo(myLocation.getMyLocation());
mc.setZoom(17);
mc = mapView.getController();
lat = myLocation.getMyLocation().getLatitudeE6();
lng = myLocation.getMyLocation().getLongitudeE6();
Toast.makeText(
getBaseContext(),
"My Location : Latitude = " + lat + " Longitude = "
+ lng, Toast.LENGTH_LONG).show();
}
});
mapView.getOverlays().add(myLocation);
}

@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) {
}

}

这是我的 list

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.manita.maptest"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="3" />

<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<uses-library android:name="com.google.android.maps" />
<activity
android:name=".MaptestActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_GPS" />
<uses-permission android:name="android.permission.ACCESS_COARSE" />
<uses-permission android:name="android.permission.LOCATION" />

</manifest>

这里是 logcat 中的错误

01-10 10:37:47.765: E/Sensors(5222): ####### akmd2 started!!!
01-10 10:37:47.770: E/SensorManager(5222): registerListener 0:AK8973 Compass
01-10 10:37:47.950: E/SensorManager(5222): =======>>>>>>> Sensor Thread RUNNING <<<============================
01-10 10:37:47.995: I/MapActivity(5222): Handling network change notification:CONNECTED
01-10 10:37:47.995: E/MapActivity(5222): Couldn't get connection factory client

谢谢

最佳答案

我遇到了同样的问题

获取 GPS 信号时无需扩展 MapActivity

然后使用Activity,转发到MapActivity

虽然不知道原因:(

关于android获取当前位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8801924/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com