Location not being updated on new geo fix in android emulator

寵の児 提交于 2019-12-12 02:02:22

问题


I am trying to make it so a MapView zooms to a current location based on a GeoPoint. I am setting the location using the geo fix command in telnet. My problem is that when I first input a location using geo fix my code will correctly navigate to a location on the map. If I try to set another location using geo fix however it does not update. Here is the code to update:

public void updateLocation(Location loc) {
    p = new GeoPoint((int)(loc.getLongitude() * 1E6),(int)(loc.getLatitude() * 1E6));

    mc = mapView.getController();

    mc.animateTo(p);
}

and here is my code to call the update:

LocationListener onLocationChange=new LocationListener() {
    public void onLocationChanged(Location location) {
        updateLocation(location);
    }

etc...

I have the following in onResume():

    super.onResume();
    myLocationManager.requestLocationUpdates("gps", 0, 200, onLocationChange);

The points I am trying to geo fix to are far enough apart to meet the minimum distance requirement. Anyone have any ideas of what I'm missing?


回答1:


Call mapView.invalidate(); (see View:invalidate()) or mapView.postInvalidate(); (see View:postInvalidate()), depending on if it runs on UI thread or not, after

mc.animateTo(p);



回答2:


Assuming your MapActivity implements LocationListener, then change

myLocationManager.requestLocationUpdates("gps", 0, 200, onLocationChange);

to

myLocationManager.requestLocationUpdates("gps", 0, 200, this);

'this' holds the location listener



来源:https://stackoverflow.com/questions/3858743/location-not-being-updated-on-new-geo-fix-in-android-emulator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!