简体   繁体   中英

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. 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. Thank you!

You can get the LatLng of the position of the center of the google map. 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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