简体   繁体   English

位置未在Android模拟器中的新地理位置修复程序上更新

[英]Location not being updated on new geo fix in android emulator

I am trying to make it so a MapView zooms to a current location based on a GeoPoint. 我正在尝试使MapView能够基于GeoPoint缩放到当前位置。 I am setting the location using the geo fix command in telnet. 我正在使用telnet中的geo fix命令设置位置。 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(): 我在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? 有人对我缺少的东西有任何想法吗?

Call mapView.invalidate(); 调用mapView.invalidate(); (see View:invalidate() ) or mapView.postInvalidate(); (请参见View:invalidate()mapView.postInvalidate(); (see View:postInvalidate() ) , depending on if it runs on UI thread or not, after (请参阅View:postInvalidate() ,具体取决于它是否在UI线程上运行,之后

mc.animateTo(p);

Assuming your MapActivity implements LocationListener, then change 假设您的MapActivity实现了LocationListener,然后进行更改

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

to

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

'this' holds the location listener “ this”保存位置监听器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM