美文网首页
RN地图插件使用

RN地图插件使用

作者: Bana | 来源:发表于2018-09-26 16:57 被阅读290次

React Native
环境:rn 0.55.3
react-native-amap-geolocation 0.3.0

Geolocation
官方说明:

译注 1:本 API 在安卓上需要谷歌框架支持,因而无法在国内使用,请在 github 上搜索百度或高德等国内第三方封装替代库。

所以本人在部分安卓机上也遇到了这个情况,所以决定使用第三方插件,选择了
高德地图插件:react-native-amap-geolocation

使用方法可以看git上写的很清楚
下面说遇到的问题
1.定位并没有传回城市,街道和地址
解决方案:将获取到的 经纬度 通过第三方库 逆地理编码 从而获取详细信息,

//          例如:我用的腾讯,通过链接获取地址信息,用fetch就可以获取了:
 
http://apis.map.qq.com/ws/geocoder/v1/?key=yourkey&get_poi=0&location=' + latitude + ',' + longitude + ''

2.ios打包的时候 遇到了 库冲突,duplicate错误,不能archive等问题

解决方案:参考官方推荐
最终修改:修改Pod文件如下

platform :ios, '8.0'

target 'project' do

   pod 'React', :path => '../node_modules/react-native'
   pod 'React', :path => '../node_modules/react-native', :subspecs => [
   'Core',
   'DevSupport',
   'CxxBridge',
   ]
   pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
   # Third party deps podspec link
   pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
   pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
   pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
   pod 'react-native-amap-geolocation', path: '../node_modules/react-native-amap-geolocation/lib/ios'
end

post_install do |installer|
   installer.pods_project.targets.each do |target|
       if target.name == "React"
           target.remove_from_project
       end
       if target.name == "yoga"
           target.remove_from_project
       end
   end
end

相关文章

网友评论

      本文标题:RN地图插件使用

      本文链接:https://www.haomeiwen.com/subject/yfkjoftx.html