[英]Android locationlistener doesn't work on android device
My location listener works when I am using the DDMS controls in the emulator but when I deploy it onto the phone it no longer works. 当我在模拟器中使用DDMS控件时,我的位置侦听器可以工作,但是当我将其部署到手机上时,它将不再起作用。 My code is as follows
我的代码如下
public class hoosheerAndroidAct extends MapActivity implements LocationListener {
/** Called when the activity is first created. */
MapController mc;
public static MapView gMapView = null;
GeoPoint p = null;
static double latitude, longitude;
MyLocationOverlay myLocationOverlay;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.screen1);
// Creating and initializing Map
gMapView = (MapView) findViewById(R.id.mapview);
p = new GeoPoint((int) (latitude * 1E6),
(int) (longitude * 1E6));
gMapView.setSatellite(true);
gMapView.setBuiltInZoomControls(true);
mc = gMapView.getController();
mc.setCenter(p);
mc.setZoom(11);
myLocationOverlay = new MyLocationOverlay(this, gMapView);
gMapView.getOverlays().add(myLocationOverlay);
list = gMapView.getOverlays();
list.add(myLocationOverlay);
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000L, 5.0f,
this);
}
methods implemented for implements LocationListener
为
implements LocationListener
实现的方法
public void onLocationChanged(Location location) {
if (location != null) {
GeoPoint point = new GeoPoint((int) (location.getLatitude() * 1E6),
(int) (location.getLongitude() * 1E6));
mc.animateTo(point);
connect("http://api.foursquare.com/v1/venues.json?geolat="
+ location.getLatitude() + "&geolong="
+ location.getLongitude());
Drawable marker = getResources().getDrawable(R.drawable.marker);
gMapView.getOverlays().add(new SitesOverlay(marker));
}
}
public void onProviderDisabled(String provider) {
// required for interface, not used
}
public void onProviderEnabled(String provider) {
// required for interface, not used
}
public void onStatusChanged(String provider, int status, Bundle extras) {
// required for interface, not used
}
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
Is there anything I am missing? 我有什么想念的吗? :-(
:-(
Maybe you are testing in door,can't get gps information. 也许您正在门内测试,无法获取gps信息。 try to change LocationManager.GPS_PROVIDER-->LocationManager.NETWORK_PROVIDER.
尝试更改LocationManager.GPS_PROVIDER-> LocationManager.NETWORK_PROVIDER。
I had a similar problem and try everything in programming. 我遇到了类似的问题,请尝试编程中的所有内容。 I read about that google use same other sensors to find location.
我了解到该Google使用相同的其他传感器来查找位置。 I even find mobile where location listener won't work in google maps.
我什至在谷歌地图上找不到位置侦听器的手机。 When I checked the settings i accedently turn on battery power saving and location listener starts.
当我检查设置时,我同意打开电池节电功能并启动位置监听器。 On some other device where location wan't work too I turn on buttery saving and location is shown.
在某些位置也不起作用的其他设备上,我打开了黄油保存功能,并显示了位置信息。 I don't know why is that, but buttery maybe will save your app.
我不知道为什么,但是黄油可能会节省您的应用程序。
its because when your device is not able to find location it return default location 0,0. 这是因为当您的设备找不到位置时,它将返回默认位置0,0。 better you check your device gps connection by checking other apps like map app of your device
最好通过检查其他应用(例如设备的地图应用)来检查设备的GPS连接
Google maps will default to network location provider if the GPS is unable to find a signal so that test could return a location without a GPS signal. 如果GPS无法找到信号,则Google地图将默认为网络位置提供商,以便测试可以返回没有GPS信号的位置。 I would recommend GPS Status as a good free app.
我会建议GPS状态作为一个很好的免费应用程序。 The only other thing I can think of is to make sure you have a clear view of the sky.
我能想到的唯一的另一件事是确保您对天空有清晰的视野。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.