This example usage MapLibre GL SDK for React Native.
Example showcase Baato API usage for
- Search (Autocomplete)
- Reverse-search
- Map tile and style
- Place
- Direction
"dependencies": {
"@mapbox/polyline": "^1.1.1",
"@maplibre/maplibre-react-native": "^9.0.0",
"@turf/turf": "^6.5.0",
"react": "18.2.0",
"react-native": "0.71.3"
}
Obtain baatoToken from https://baato.io/account
Herequeryparameter
isq
Number of search result perq
is indicated bylimit
which is20
for this example
fetch(`https://api.baato.io/api/v1/search?key=${baatoToken}&q=${text}&limit=20`)
.then(response => response.json()
.then(data => {
setResult(data.data);
}).catch(error => {
console.error(error);
}))
Full implementation of this code is available on github
In this example
pressCoord
islatitude and longitude
for reverse geocoding
useEffect(() => {
fetch(`https://api.baato.io/api/v1/reverse?key=${baatoToken}&lat=${pressCoord.lat}&lon=${pressCoord.lon}`)
.then(response => response.json()
.then(data => {
console.log(data.data[0]);
placeDetail = data.data;
}).catch(error => {
setMarkerVisible(false);
console.error(error);
}));
}, [pressCoord]);
Full implementation of this code is available on github
For requesting place detail
placeId
is needed which can be obtained fromsearch
orreverse-search
fetch(`https://api.baato.io/api/v1/places?key=${baatoToken}&placeId=${placeResult.placeId}`)
.then(response => response.json()
.then(data => {
placeDetail = data.data;
}).catch(error => {
console.error(error);
}));
Full implementation of this code is available on github
styleURL
can be obtained from baato
<MapLibreGL.MapView
styleURL="https://api.baato.io/api/v1/styles/outdoor?key=${baatoToken}"
style={styles.map}
logoEnabled={false}
attributionEnabled={false}
/>
Full implementation of this code is available on github
For requesting direction API, array of coordinate i.e
points[]
in this setup, and mode are required parameters.
IfforMapbox = true and instructions = true
are set then the response and instructions are in detail and similar to mapbox navigation.
The route isencoded polyline
with precision level of6
so, if points are needed then can usepolyline decoder
as shown below.
fetch(
`https://api.baato.io/api/v1/directions?key=${baatoToken}`
+ `&points[]=${poiDetail.centroid.lat},${poiDetail.centroid.lon}`
+ `&points[]=${userCoord.lat},${userCoord.lon}`
+ `&mode=foot`
+ `&alternatives=false`
+ `&forMapbox=true`
+ `&instructions=true`
+ `&locale=en_US`)
.then(response => response.json()
.then(data => {
setQueryRoute(!queryRoute);
const route = polyline.toGeoJSON(`${data.data.routes[0].geometry}`, 6);
setRouteCoord(route);
}).catch(error => {
console.error(error);
}));
Full implementation of this code is available on github