Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Directions API call ? react-native

Tags:

react-native

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?

like image 996
invariant Avatar asked Jul 21 '15 09:07

invariant


People also ask

Is Google Directions API free?

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.

Is Google Map API free for react native?

"Embedding Google Maps through react-native-maps does require an API key, but it is at no cost.


2 Answers

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

like image 106
Colin Ramsay Avatar answered Nov 04 '22 21:11

Colin Ramsay


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);
        }
    })();
}
like image 33
Jean-Claude YALAP Avatar answered Nov 04 '22 21:11

Jean-Claude YALAP