开发者

Performance issue on Android's MapView Navigation-App

I've got a question on making an navigation app more faster and more stable.

The basic layer of my app is a simple mapview, covered with several overlays (2 markers for start and destination and one for the route).

My idea is to implement a thread to display the route, so that the app won't hang up during the calculation of a more complex route (like it does right now).

After implementing the thread there are no updates shows any more, maybe you can help me with a short glance at an excerpt of my code below:

    private class MyLocationListener implements LocationListener {
    @Override
    public void onLocationChanged(Location loc) {
        posUser = new GeoPoint((int) (loc.getLatitude() * 1E6), (int) (loc
                .getLongitude() * 1E6));

        new Thread(){
        public void run(){
            mapView.invalidate();

            // Erase old overlays
            mapVi开发者_运维知识库ew.getOverlays().clear();

            // Draw updated overlay elements and adjust basic map settings
            updateText();
            if(firstRefresh){
                adjustMap();
                firstRefresh = false;
            }
            getAndPaintRoute();
            drawMarkers();
        }
        };
    }

Some features have been summarized to a method like "drawMarkers()" or "updateText()"...(they don't need any more attention ;-))


When are you actually asking for the thread to run? I only see code for creating it. If you did, you'd discover that only the main (UI) thread is allowed to update, as RPond notes.

Instead, split off your work and post the results back to the main thread via a Handler.


You can only update the UI on the UI thread so I think that is the problem. Check out this article on threading for solutions to this problem.


I may be barking up the wrong tree here, but my guess is that it's something to do with the fact that you're making changes to the MapView on a thread that isn't the UI thread.

I'd expect this to result in one of these possibilities:

  • Your changes are throwing an exception that you're not seeing (again possibly because it's on another thread)
  • Your changes are being ignored because they're being made on the wrong thread.
  • The map's being updated but your UI thread doesn't know it needs to redraw the map.

Hope this helps - at least by pointing you in vaguely the right direction.


One would hope you're not using the Google MapView for rendering your navigation, since from my reading of the terms and conditions, navigation is not included in the acceptable use policy.

From the Android Maps APIs Terms of Service

Under this Section 8, you must not (nor may you permit anyone else to):

...

8.7. use the Service or Content with any products, systems, or applications for or in connection with (a) real time navigation or route guidance based on position input from a sensor (including but not limited to any visual or audible turn-by-turn route guidance);

...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜