【问题标题】:React native google maps反应原生谷歌地图
【发布时间】:2020-02-24 04:51:47
【问题描述】:

在我的反应原生应用程序中。一旦用户在我的应用程序中按下按钮,我想打开标准的谷歌地图应用程序并显示特定的位置。我该怎么做呢

【问题讨论】:

标签: react-native google-maps


【解决方案1】:

解决方案

openGps = (lat, lng) => {
  var scheme = Platform.OS === 'ios' ? 'maps:' : 'geo:';
  var url = scheme + `${lat},${lng}`;
  Linking.openURL(url);
}

相应地传递纬度和经度

或者如果你想使用自定义标签试试这个:

const scheme = Platform.select({ ios: 'maps:0,0?q=', android: 'geo:0,0?q=' });
const latLng = `${lat},${lng}`;
const label = 'Custom Label';
const url = Platform.select({
  ios: `${scheme}${label}@${latLng}`,
  android: `${scheme}${latLng}(${label})`
});


Linking.openURL(url);

【讨论】:

    【解决方案2】:

    安装“react-native-navigation-directions”并使用下面的代码。 点击你的按钮调用_callShowDirections,它会将你重定向到标准的谷歌地图应用程序。

    import { OpenMapDirections } from 'react-native-navigation-directions';
    
    //Use this function 
      _callShowDirections = () => {
         const startPoint = {
           longitude: 'START_POINT_LONGITUDE',
           latitude: 'START_POINT_LATITUDE'
         } 
    
         const endPoint = {
           longitude: 'END_POINT_LONGITUDE',
           latitude:  'END_POINT_LATITUDE'
         }
    
        const transportPlan = 'd';
    
        OpenMapDirections(startPoint, endPoint, transportPlan).then(res => {
          console.log(res)
        });
      }
    

    【讨论】:

      猜你喜欢
      • 2020-02-20
      • 2021-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-10
      • 2017-12-22
      • 2020-03-02
      相关资源
      最近更新 更多