获取路线API电话?反应母语

inv*_*ant 13 react-native

在许多iOS应用程序中,我可以看到一个按钮,说明getDirections,点击后会打开经过目的地的纬度和经度的Apple/Google地图.

我的TouchableHighlight按钮有lat和lng准备好了.我需要在onPress回调中调用什么API端点来打开Apple坐标作为路径目的地的坐标?

Col*_*say 15

要链接到其他应用程序(例如地图),请使用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);
Run Code Online (Sandbox Code Playgroud)

对于地图,URL方案与标准Obj-C应用程序相同:

https://developer.apple.com/library/ios/featuredarticles/iPhoneURLScheme_Reference/MapLinks/MapLinks.html

  • 要实际启动导航,请使用适用于iOS的http://maps.apple.com/?daddr= <lat>,<long>`和`http://maps.google.com/maps?daddr= <lat> ,<long>`适用于Android. (6认同)
  • LinkingIOS已被弃用.请改为使用[链接](https://facebook.github.io/react-native/docs/linking.html). (3认同)

Jea*_*LAP 7

要链接到其他应用程序,并将行程打开为地图,请使用此功能:

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);
        }
    })();
}
Run Code Online (Sandbox Code Playgroud)