Reputation: 2789
I'm trying to create the following algorithm below but I'm not sure how I can get started, hence not having any code here:
The goal is to display (for example 30 stores from Google Maps). I'm currently using Google Maps API in the app.
The Algorithm:
Retrieve 30 different stores based on the level of zoom.
Example 1: if the zoom is at 10 (City Zoom) show 30 different stores at that specific zoom. These stores will cover different lats and long from the Map. (ideally cover North, South, East, and West from what's the user is currently seeing in the map).
Example 2: if the user zooms to level 15, (Street Zoom) it will also display these 30 stores at that specific zoom. If not 30 stores, it will display (< 30).
Any help will be appreciate. If more clarification necessary, comment and I will bring modifications to the post.
Upvotes: 0
Views: 653
Reputation: 13343
You can do it simply by modification of the map style: Adding a Styled Map
- Create JSON file src\main\res\raw\map_style.json like this:
[ { featureType: "poi", elementType: "labels", stylers: [ { visibility: "off" } ] } ]
- Add map style to your
GoogleMap
googleMap.setMapStyle(MapStyleOptions.loadRawResourceStyle(getContext(), R.raw.map_style));
You can use Place Search from Google Places API and get list of points of interest via nearby URL request:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=<LAT_LNG>&types=point_of_interest&radius=<RADIUS_IN_METERS>&sensor=false&key=<YOUR_APP_KEY>
parse it.
NB! Nearby URL request returns only 20 places, for load more data you should use string value from next_page_token
tag of response and pass it via pagetoken
parameter for next request:
https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=<LAT_LNG>&types=point_of_interest&radius=<RADIUS_IN_METERS>&sensor=false&key=<YOUR_APP_KEY>&pagetoken=<TOKEN_FOR_NEXT_PAGE_FROM_next_page_token_TAG_OF_RESPONSE>
rating
or other field or by other custom criteria. And seems, if user change zoom from 10 to 15 all stores shown at zoom 10 should still be visible.Upvotes: 1