Android MapView POI Caching Strategy

匆匆过客 提交于 2021-01-28 06:41:45

问题


I have an Android app that when launched, inflates a MapView, gets the user's location and then makes a request to my server to fetch all points of interest (POI) as JSON within some radius of their location and draws those points on the map. I want the user to be able to pan around the map and see more points of interest load as they go outside of that initial data load, just like Google maps.

My initial thought is to handle the pan event and when panning stops, get the map center, and make another server request for POI within some radius of that location. This seems to me like this will quickly get to a point where it's sending back redundant data and making unnecessary server requests.

I'm looking for a caching strategy where I can make requests to fetch new data, but not have to make additional requests for the same data. My POI don't change very often either, so caching would be ideal to speed up subsequent launches of my app. Are there any best practices out there for such a thing? Or is it preferred to make a larger data request up front and just fetch new data as necessary?


回答1:


What spontaneously comes to my mind is sectioning the POIs in square tiles for example. These tiles have a lastUpdate timestamp and both client and server communicate in terms of tiles, instead of geo location center point and radius. Your client would always send the lastUpdate timestamp of the cached tiles to the server and the server would only respond with updated data when that timestamp did change for the requested tiles. Another advantage is that your algorithm for retrieving POIs would be way faster compared to "point in circle" calculations.

Your client app can decide when to re-request tiles based on the timestamp. That depends on how often your server data changes. If it changes just once per day, then let your app re-request cached tiles only once per day. My suggestion is based on a fixed size tile (like 2 square miles for example). Otherwise you'll have a hard time with keeping track of the lastUpdate time stamps. You could however create something like several different "levels of detail" for your zoom levels or your app needs to calculate the upper left visible tile and the lower right visible tile depending on the current zoom.



来源:https://stackoverflow.com/questions/11511638/android-mapview-poi-caching-strategy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!