开发者

Android app's map pins not appearing until screen is touched

开发者 https://www.devze.com 2023-01-18 17:09 出处:网络
I am experiencing a problem with my app. The 1st screen that appears is a map that d开发者_如何学运维isplays pins that are located based on an XML file that is loaded from our server.

I am experiencing a problem with my app. The 1st screen that appears is a map that d开发者_如何学运维isplays pins that are located based on an XML file that is loaded from our server.

Sometimes the app loads as expected. Other times, the map loads but none of the pins appear until you touch the screen.

Any ideas why this may be happening and what can be done to fix the problem?


Sometimes the app loads as expected. Other times, the map loads but none of the pins appear until you touch the screen.

If I had to guess, it's a timing thing -- sometimes, your server responds fast enough that the pins get picked up in the initial map rendering, sometimes not. I do not know how you have implemented the server-fetch and pin-popluation, but call populate() on your ItemizedOverlay (assuming that is what you are using) after your pins are ready, then if needed call invalidate() on the MapView.


I had a similar problem in one of my projects. The Overlay would draw itself properly on my test phone (Samsung G5) but, on the emulator the overlay would only appear after an action on my part (like a screen touch). I later tested the same project on a Nexus One and the behavior was the same then on the emulator.

I now force a redraw of the MapView by calling invalidate() on the mapview once the Overlay is populated as mentioned by CommonsWare.


how many pins are there on map??? if there are many pins then use populate only once after pins are ready otherwise it will take time every populate statement takes a lot of time so use populate only once


Another approach to solving this could be to add a GoogleMap.OnMapLoadedCallBack() to initialize your display. Then the timing issue goes away completely.

0

精彩评论

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