Android MapView POI缓存策略 [英] Android MapView POI Caching Strategy

查看:63
本文介绍了Android MapView POI缓存策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Android应用程序,该应用程序在启动时会膨胀MapView,获取用户的位置,然后向我的服务器发出请求,以获取所有感兴趣的点(POI)作为JSON在其所在位置的半径范围内,并在这些点上绘制这些点地图.我希望用户能够像平移谷歌地图一样平移地图并看到更多兴趣点,因为它们超出了初始数据负荷.

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.

我最初的想法是处理平移事件,当平移停止时,获取地图中心,并在该位置的某个半径范围内再次向服务器请求POI.在我看来,这似乎很快就会达到发送冗余数据并发出不必要的服务器请求的地步.

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.

我正在寻找一种缓存策略,可以在其中请求获取新数据的请求,而不必对同一数据进行其他请求.我的POI也不经常更改,因此缓存将是加快我的应用程序后续启动的理想选择.有没有关于这种事情的最佳实践?还是更愿意预先发出更大的数据请求,然后根据需要获取新数据?

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?

推荐答案

例如,我自发想到的是将POI切成正方形方块.这些磁贴具有lastUpdate时间戳,并且客户端和服务器都根据磁贴而不是地理位置中心点和半径进行通信.您的客户端将始终将缓存的切片的lastUpdate时间戳发送到服务器,并且服务器仅在该时间戳确实更改了所请求的切片时才响应更新的数据.另一个优点是,与点对点"计算相比,检索POI的算法要快得多.

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.

您的客户端应用可以根据时间戳决定何时重新请求图块.这取决于您的服务器数据更改的频率.如果它每天仅更改一次,则让您的应用每天仅重新请求一次缓存的切片.我的建议是基于固定大小的图块(例如2平方英里).否则,您将很难跟踪lastUpdate时间戳.但是,您可以为缩放级别创建类似几个不同的细节级别",或者您的应用需要根据当前缩放来计算左上可见图块和右下可见图块.

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.

这篇关于Android MapView POI缓存策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆