{"id":187919,"date":"2020-11-09T11:50:28","date_gmt":"2020-11-09T03:50:28","guid":{"rendered":"http:\/\/4563.org\/?p=187919"},"modified":"2020-11-09T11:50:28","modified_gmt":"2020-11-09T03:50:28","slug":"%e8%af%b7%e9%97%ae-rn-%e7%9a%84-geolocation-%e6%8f%90%e4%be%9b%e7%9a%84%e5%ae%9a%e4%bd%8d%e6%96%b9%e6%b3%95%e5%9c%a8%e5%ae%89%e5%8d%93%e4%b8%8a%e4%b8%8d%e5%87%86%e7%9a%84%e9%97%ae%e9%a2%98%e5%a4%a7","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=187919","title":{"rendered":"\u8bf7\u95ee RN \u7684 Geolocation \u63d0\u4f9b\u7684\u5b9a\u4f4d\u65b9\u6cd5\u5728\u5b89\u5353\u4e0a\u4e0d\u51c6\u7684\u95ee\u9898\u5927\u5bb6\u662f\u600e\u4e48\u89e3\u51b3\u7684\u5440\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u8bf7\u95ee RN \u7684 Geolocation \u63d0\u4f9b\u7684\u5b9a\u4f4d\u65b9\u6cd5\u5728\u5b89\u5353\u4e0a\u4e0d\u51c6\u7684\u95ee\u9898\u5927\u5bb6\u662f\u600e\u4e48\u89e3\u51b3\u7684\u5440\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : HariopaNic <\/span>  <span><i><\/i> 7<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\">                        \u76ee\u524d\u4f7f\u7528\u7684\u662f import Geolocation, { GeolocationError, GeolocationResponse } from &#8216;@react-native-community\/geolocation&#8217;;<\/p>\n<p>function getLocation() {<br \/> return new Promise&lt;Location&gt;((resolve) =&gt; {<br \/> Geolocation.getCurrentPosition(<br \/> (info: GeolocationResponse) =&gt; {<br \/> \/\/ console.log(`[Geolocation] location: ${JSON.stringify(info)}`);<br \/> let location = info.coords;<br \/> \/\/ \u5730\u7403\u5750\u6807\u7cfb\u8f6c\u706b\u661f\u5750\u6807\u5668<br \/> var marsLocation = wgs2mars(location);<br \/> resolve(marsLocation);<br \/> },<br \/> (error: GeolocationError) =&gt; {<br \/> global.log(`[Geolocation] error: ${error.message}`);<br \/> resolve({} as Location);<br \/> },<br \/> );<br \/> });<br \/>}<br \/>\u53d1\u73b0\u5728\u5b89\u5353\u673a\u4e0a\u6709\u4ee5\u4e0b\u95ee\u9898\uff1a<br \/>1\uff0c\u5982\u679c\u5c06\u9ad8\u7cbe\u5ea6 enableHighAccuracy \u8bbe\u7f6e\u4e3a true \u7684\u8bdd\uff0c\u5728\u5b89\u5353\u673a\u5b50\u4e0a\u5c06 gps \u5173\u95ed\u540e\u518d\u6253\u5f00\u4f1a\u8bc6\u522b\u4e0d\u5230 gps \u6253\u5f00\uff0c\u62ff\u5230\u7684\u6570\u636e\u4e00\u76f4\u4e3a{}\uff08\u6211\u7528\u662f\u5426\u4e3a{}\u5224\u65ad gps \u5f00\u5173\u72b6\u6001\uff09\u3002<br \/>2\uff0c\u5f53\u6211\u628a\u7ecf\u7eac\u5ea6\u6253\u5728\u5c4f\u5e55\u4e0a\u6d4b\u8bd5\uff0cios \u673a\u578b\u4f1a\u968f\u7740\u8d70\u52a8\u53d8\u5316\u7ecf\u7eac\u5ea6\uff0c\u4f46\u662f\u5b89\u5353\u673a\u578b\u53ef\u80fd\u8fc7\u4e86\u5343\u7c73\u624d\u4f1a\u53d8\u52a8\u4e00\u6b21\uff0c\u4e14\u5341\u5206\u4e0d\u51c6\u5907\u3002<br \/>\u5df2\u505a\u5730\u7403\u5750\u6807\u7cfb\u8f6c\u706b\u661f\u5750\u6807\u5668\u5904\u7406\u3002<\/p>\n<p>\u8bf7\u95ee\u5927\u5bb6\u505a app \u7aef\u5b9a\u4f4d\u9700\u6c42\u7684\u65f6\u5019\u662f\u600e\u4e48\u5904\u7406\u7684\u5440\uff1f\u5927\u611f\u8c22\u3002      <\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>1<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4020358\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : HariopaNic <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             nobody- &#8211;                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u8bf7\u95ee RN \u7684 Geolocati&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/187919"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=187919"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/187919\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=187919"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=187919"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=187919"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}