1

我正在使用 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);

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

4

1 回答 1

0

According to this SO post the GeoPoint may be getting constructed incorrectly, this could cause an incorrect location. As for the LocationManager, the requestLocationUpdates method is only getting run once, meaning it's taking the EditText's value when the the method was run, it will not update unless you tell it to. There might be a method inside the the LocationManager class to do that.

EDIT

Ignore the part about the GeoPoint, upon further reading you are correct in multiplying your long/lat by 1000000

于 2012-06-04T15:51:26.780 回答