In many iOS apps I can see a button saying getDirections, which will upon click open an Apple/Google maps with latitude and longitude passed as destination.
I have my TouchableHighlight
button with lat and lng ready. What API endpoint do I need to call in onPress
callback to open Apple maps with my coordinates as route destination?
The Directions API uses a pay-as-you-go pricing model. Directions API requests generate calls to one of two SKUs depending on the type of request: basic or advanced. Along with the overall Google Terms of Use, there are usage limits specific to the Directions API.
"Embedding Google Maps through react-native-maps does require an API key, but it is at no cost.
To link to another application, such as Maps, use LinkingIOS:
https://facebook.github.io/react-native/docs/linkingios.html
// Replace lat and long with your own decimal latitude and longitude values
var url = 'http://maps.apple.com/?ll=<lat>,<long>';
LinkingIOS.openURL(url);
For maps the URL scheme is just the same as from a standard Obj-C app:
https://developer.apple.com/library/ios/featuredarticles/iPhoneURLScheme_Reference/MapLinks/MapLinks.html
To link to another application, and open itinerary as Maps, use this function:
export function openDirections(latitude, longitude) {
Platform.select({
ios: () => {
Linking.openURL('http://maps.apple.com/maps?daddr=' + latitude + ',' + longitude);
},
android: () => {
Linking.openURL('http://maps.google.com/maps?daddr=' + latitude + ',' + longitude);
}
})();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With