简体   繁体   中英

Displaying stores based on zoom level from Google Maps API

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.

  1. Before showing stores you need to hide "standard" markers, like in this answer of Jozef :

You can do it simply by modification of the map style: Adding a Styled Map

  1. Create JSON file src\\main\\res\\raw\\map_style.json like this:

 [ { featureType: "poi", elementType: "labels", stylers: [ { visibility: "off" } ] } ] 
  1. Add map style to your GoogleMap

 googleMap.setMapStyle(MapStyleOptions.loadRawResourceStyle(getContext(), R.raw.map_style)); 
  1. 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>
  1. You can select 30 stores from the list by 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.

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