【问题标题】:Location not accurate and geting an exception in the DDMS位置不准确并在 DDMS 中出现异常
【发布时间】:2012-08-21 07:56:27
【问题描述】:

我正在使用 osmdroid 显示来自 MAPNIK 的地图并将地图的中心设置在特定位置 应用程序没有错误,但地图的中心位置远离我在代码中指定的点,我从我需要的代码中设置了位置(纬度和经度),我不想这样从 DDMS 发送它们,我的代码是:

Double latitude = 15.610793;
Double longitude =  32.540152;
int lat = (int) (latitude * 1E6); 
int lng = (int) (longitude * 1E6); 
GeoPoint myPoint = new GeoPoint(lat, lng); 
// show first message
Toast toast = Toast.makeText(getBaseContext(),
    "latitude is :"+lat+"lng is: "+lng, Toast.LENGTH_LONG);
toast.show();


    mapView = (MapView) this.findViewById(R.id.mapView); 
    mapView.setTileSource(TileSourceFactory.MAPNIK); 
    mapView.setBuiltInZoomControls(true); 
    mapView.setMultiTouchControls(true);
    mapController = mapView.getController();
    mapController.setCenter(myPoint);
    mapController.setZoom(15);

我在模拟器中也有这个错误:

[2012-06-16 00:05:21 - ddms] null
java.lang.NullPointerException
at com.android.ddmlib.Client.sendAndConsume(Client.java:573)
at com.android.ddmlib.HandleHello.sendHELO(HandleHello.java:142)
at com.android.ddmlib.HandleHello.sendHelloCommands(HandleHello.java:65)
at com.android.ddmlib.Client.getJdwpPacket(Client.java:672)
at com.android.ddmlib.MonitorThread.processClientActivity(MonitorThread.java:317)
at com.android.ddmlib.MonitorThread.run(MonitorThread.java:263)

[2012-06-16 00:05:21 - ddms] null
java.lang.NullPointerException
at com.android.ddmlib.Client.sendAndConsume(Client.java:573)
at com.android.ddmlib.HandleHello.sendHELO(HandleHello.java:142)
at com.android.ddmlib.HandleHello.sendHelloCommands(HandleHello.java:65)
at com.android.ddmlib.Client.getJdwpPacket(Client.java:672)
at com.android.ddmlib.MonitorThread.processClientActivity(MonitorThread.java:317)
at com.android.ddmlib.MonitorThread.run(MonitorThread.java:263)

抱歉,我提到错误不是异常,正如我所说,它在控制台中标有:DDMS,所以应用程序工作正常并且不会崩溃

【问题讨论】:

  • 我还注意到,当我在模拟器中使用 google API 测试它时,位置是准确的,我不知道为什么?
  • 我认为您必须使用 Google API 才能使用 MapView。
  • 我知道我正在使用 osmdroid api,这意味着,我不需要 GAPI

标签: android mapping location emulation


【解决方案1】:

我遇到了类似的问题。尝试颠倒以下语句的顺序:

mapController.setCenter(myPoint);
mapController.setZoom(15);

希望有帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多