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

时间:2015-07-21 09:44:11

标签: react-native

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

我的TouchableHighlight按钮已准备好lat和lng。我需要在onPress回调中调用哪个API端点来打开Apple坐标作为路线目的地的地图?

3 个答案:

答案 0 :(得分:15)

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

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

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

答案 1 :(得分:6)

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

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);
        }
    })();
}

答案 2 :(得分:-3)

您可以使用Geolocation API

Clone failed
RPC failed; result=18, HTTP code = 200
The remote end hung up unexpectedly
early EOF
index-pack failed

然后您可以使用该位置并根据需要显示它,可能在MapView