简体   繁体   English

从服务器加载谷歌地图标记的最有效方法是什么

[英]What is the most effective way to load google maps markers from server

I have a server which store hundred thousand of google maps markers details spread all over the globe, Now im trying to display them in my android app. 我有一个存储十万个谷歌地图标记详细信息的服务器遍布全球,现在我试图在我的Android应用程序中显示它们。 obviously i dont need to display the whole markers at once but just where the user is looking at and at a certain zoom. 很明显,我不需要一次显示整个标记,而只需要用户正在查看和缩放的位置。 im using json file from the server to send the markers but I didnt realize yet what the most effective way to load them as the user need. 即时通讯使用服务器的json文件发送标记,但我还没有意识到,最有效的方法是加载它们作为用户需要。 Thank you! 谢谢!

You can get the LatLng of the position of the center of the google map. 您可以获取谷歌地图中心位置的LatLng。 Then you can send the position to your server and calculate the points there are closer than a certain distance and only return those ones. 然后,您可以将位置发送到您的服务器并计算距离特定距离更近的点,并仅返回那些点。

Use something like this: 使用这样的东西:

 mGoogleMap.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() {
            @Override
            public void onCameraChange(CameraPosition cameraPosition) {
                LatLng latLng = cameraPosition.target;

                mRepository.requestPointsNearPosition(latLng)
            }
        });

So everytime your camera changes position, you reload the points. 所以每次你的相机改变位置,你重新加载点。 This way you are always showing just the relevant points in the map. 这样,您始终只显示地图中的相关点。

Maybe you can use a handle to make sure that the user stops moving the map for 0.5s the handler only trigger the action with the map stops moving... other it cancels itself if the map is moved again 也许你可以使用一个句柄来确保用户停止移动地图0.5秒处理程序只触发动作,地图停止移动...其他它取消自己如果地图再次移动

Define current user's scale and circular region around center which is few time larger that user can see. 定义当前用户在中心周围的比例和圆形区域,这是用户可以看到的较大时间。 Download markers for that region. 下载该地区的标记。 Every time user move map you check if new perspective belong to that region, draw a new circle and download icons for a area not included to previous circle 每次用户移动地图时,您都会检查新视角是否属于该区域,绘制新圆圈并下载未包含在前一个圆圈中的区域的图标

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM