问题
I'm trying to enable users to use maps offline in my react native App, I'm using react-native-maps
I want to provide the offline mode just for a predefined area (let's say a city), therefore I need to download all the needed tiles which will be a huge number of images, so I wonder if there is a way in the google map API to download an area of the map (like in google map app)?
from the documentation it is possible to enable caching, which I do the same thing (according to the doc) however, In my case I don't want to cache every place that the user go to, as I said I just want to cache/download a predefined area.
EDIT 1
react-native-maps support offline navigation for that, I need to use this code :
<LocalTile pathTemplate={this.state.pathTemplate} tileSize={256}/>
with pathTemplate point to my tiles location which had to have the following hierarchy :
location/{z}/{x}/{y}
therefore my real probleme is how to get the tiles for my area.
I can do it manually by saving tiles from the google maps tile server, however I don't know if it is legal and also it will take a lot of time and calculation (when zooming in, I need to calculate the coordinated of the next tiles )
so It will be nice, if google map API provide a way to download an area's tile (with needed zoom),
another alternative would be using another map provider like OpenStreetMAp, but here also, I need to find a way to download all tiles at once
回答1:
At this time the only offline react-native module that supports offline mapping is react-native-mapbox-gl.
<MapView>
<LocalTile
pathTemplate="../pathToLocalStoredTile.png"
tileSize={126}
/>
</MapView>
This might give you some support.
As Google Maps SDK does not have this implemented, the only offline possibility is to use custom tiles.
来源:https://stackoverflow.com/questions/57260926/how-to-use-google-maps-offline-in-react-native