【问题标题】:Getting wrong gps location using locationMangager android使用locationMangager android获取错误的gps位置
【发布时间】:2012-06-04 15:44:11
【问题描述】:

我正在使用 mapView 和 LocationManager 制作一个小的 Android 应用程序。 我的 LocationManager 应该监听位置并通知我的位置是否超过了用户定义的容差。 如果我的 LocationManager 注意到位置发生变化,它应该发送一条短信。

lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000L, Float.parseFloat(txtToleranz.getText().toString()), this);

这里我不确定 requestLocationUpdates 方法是始终采用文本字段的当前值还是只采用给定的起始值...?

我的应用程序也应该在 mapView 中显示我的位置,但位置完全错误......为什么?我在真实设备上运行我的应用程序。

                double lat = location.getLatitude();
            double lng = location.getLongitude();

            String currentLocation = " Lat: " + lat + " Lng: " + lng + " Tol: " + Toleranz;
            point = new GeoPoint((int) lat * 1000000, (int) lng * 1000000);
            mapController.animateTo(point);
            mapController.setZoom(15);
            System.out.println(currentLocation);

感谢您的帮助! 最好的问候丹尼尔

【问题讨论】:

    标签: android gps location locationmanager


    【解决方案1】:

    根据this SO postGeoPoint 的构造可能不正确,这可能会导致位置不正确。至于LocationManagerrequestLocationUpdates 方法只运行一次,这意味着它在运行该方法时采用EditText's 值,除非您告诉它,否则它不会更新。 LocationManager 类中可能有一个方法可以做到这一点。

    编辑

    忽略有关 GeoPoint 的部分,在进一步阅读后,您将 long/lat 乘以 1000000 是正确的

    【讨论】:

    • 您知道如何更好地使用 GeoPoint 或类似的东西吗?
    • 为什么不将纬度/经度传递给用户地图应用程序并让它显示呢?我以前用过像Intent maps = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("geo:0,0?q="+latitude+","+longitude+" (Your location)")); maps.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity"); startActivity(maps); 这样的峰会。效果很好。
    • 我应该在哪里实现这个?哪种方法?
    • 当你的 long/lat 被分配时。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-05
    • 1970-01-01
    • 2015-05-17
    • 1970-01-01
    • 1970-01-01
    • 2013-05-06
    • 2016-07-30
    相关资源
    最近更新 更多