【问题标题】:Location not being updated on new geo fix in android emulator位置未在 android 模拟器中的新地理修复上更新
【发布时间】:2012-11-01 17:47:19
【问题描述】:

我正在尝试使 MapView 基于 GeoPoint 缩放到当前位置。我正在使用 telnet 中的 geo fix 命令设置位置。我的问题是,当我第一次使用地理修复输入位置时,我的代码将正确导航到地图上的某个位置。如果我尝试使用 geo fix 设置另一个位置,但它不会更新。这是要更新的代码:

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

    mc = mapView.getController();

    mc.animateTo(p);
}

这是我调用更新的代码:

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

等等……

我在 onResume() 中有以下内容:

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

我试图地理修复的点相距足够远以满足最小距离要求。有人对我缺少什么有任何想法吗?

【问题讨论】:

    标签: java android android-emulator


    【解决方案1】:

    调用mapView.invalidate();(见View:invalidate()mapView.postInvalidate();(见View:postInvalidate(),取决于它是否在UI线程上运行,之后

    mc.animateTo(p);
    

    【讨论】:

      【解决方案2】:

      假设你的 MapActivity 实现了 LocationListener,那么就改变

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

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

      'this' 保存位置监听器

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-01-04
        • 1970-01-01
        • 1970-01-01
        • 2022-12-18
        • 2017-07-13
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多