UNI-App supports multiple third-party map positioning methods

This method supports jump third party map and positions the specified coordinates.

The APP end jumps to Baidu Map (third-party software); if there is no, jump to Gao De Map (third-party software); if it is not, open Tencent Map (UNI Belt method: UNI. Other Nesters Open Tencent Map (UNI Belt Method: UNI.OpenLocation)


Source: https: // github. COM / YAPEEE / UNI-Components
WGS84: 39.9078008469, 116.91290596

BD09: 39.915547, 116.403909

GCJ02: 39.9091591069 , 116.3974783161

Import map from ‘../ms-openmap.js’map.OpenMap (Latitude, Longitude, Name, COORD_TYPE)

Attribute Description



latitude (default GCJ-02 coordinate System)

Name COORD_TYPE Coordinate type, optional parameter. Example: gcj02, bd09, wgs84 String First, the operation platform is compiled and uni.getsysteminfosync (). Platform to determine the Android, iOS, and other platforms. /// #ifdef app-plusswitch (uni.getsysteminfosync (). Platform) {copy ‘Android’: console.log (‘running Android “) OpenMapByandroid (Latitude , Longitude, Name) Break; Case ‘iOS’: CONSOLE.LOG (‘Run iOS’) OpenMapByios (Latitude, Longitude, Name) Break; default: OpenMapBydefault (Latitude, longitude, name) console.log (‘Run in Developer Tool “) Break;} // #ENDIF // #ifndef app-plusopenmapBydefault (Latitude, longitude, name) // #ndiftips: Censored period judgment: That is, the conditions are compiled, and the different platforms are already different after the compilation package.
Longitude Sediment (default GCJ-02 coordinate system) float
first The runtime platform for judging the program, different platform calls different ways of opening a map. Under the Android and IOS platform, it is judged and opened Baidu map and Gaode map. Under other platforms, open Tencent Maps Web Edition (UNI Belt Method).
The platform is determined that there are two scenarios, one is in the compile period, one The species is judged during the running period.

Date judgment: The runtime judgment means that the code has been entered into the package, still needs to be judged at the runtime judgment platform, which can use UNI.GETSYSTEMINFOSYNC (). Platform to determine the client The environment is Android, IOS or applet development tools (using uni.getsysteminfosync () in Baidu Small Draft Development Tools, WeChat Approach Development Tools, Alipay Small Program Development Tools. Platform Return Values ​​are devTools.

Second, App Open a third party map

HTML5 + is the middleware of the SDK and the page, for the page via JS call underlayer SDK interface .

2.1, APP judges whether or not the third party application exists

/ * * Appinf: (ApplicationInf) must choose Judgment third partyThe description of the program * Android platform needs to query by setting the AppInf’s PNAME property (package name). * iOS platform needs to be queried by setting AppInf’s action attributes, you need to add a white list after iOS9, * Add (such as UrlschemewhiteList) under the Manifest.json file plus-> distribute-> apple-> UrlschemewhiteList node (such as UrlschemewhiteList: [“weixin”]). * / plus.Runtime.isapplicationExist (appinf);

2.1.1, judging whether the Baidu map application exists
Plus.Runtime.isApplicationExist ({PNAME: ‘com.baidu.baidumap’, Action: ‘Baidumap: //’}

2.1.2, judging whether the Gaode map application exists

Plus.Runtime.isApplicationExist ({PNAME: ‘com.autonavi.minimap’}, Action: ‘iOSamap: //’}

2.2, APP calls third party program open the designated URL

/ * * Description: Call the third party program Open the specified URL * Parameters: * URL: (String) The URL address you want to open * ErrorCB: (OpenerRorCallback) Optionally open the URL address failed callback * IdentiTy: (String) Optional Specify the program name of the URL address * / plus.Runtime.OpenURL (URL, ErrorCb, Identity);

2.2.1, open The actual application of tripartite procedures

Function OpenURL (URL, IDENTITY) {let newURL = Encodeuri (URL); Plus.Runtime.OpenURL (NewURL, FUNCTION (RES) {UNI.SHOWMODAL ({Content: Res.Mestage})}
 2.2.2, open Android Baidu map   

URL = `baidumap: // map / marker? Location = $ {latitude}, $ {longitude} & title = $ {name} & coord_type = gcj02 & src = andr.baidu.openapidemo`Indentity = ‘com.baidu.baidumap’Openurl (URL, IDENTIN)

2.2.3, Open Android Gao De Map
URL = `Androidamap: // viewMap? SourceApplication = Appname & Poiname = $ {Name} & lt = $ {latitude} & lon = $ {longitude} & dev = 0`Identity = ‘com.autonavi.minimap’OpenURL (URL, Identity)
2.2.4, open iOS Baidu map

 URL = `baidumap: // map / marker? Location = $ {latitude} `; OpenURL (URL, IDENTIN)   
2.2.5, open iOS Gao De Map

URL = `iOSAMAP: // viewMap? SourceApplication = ApplicationName & Poiname = $ {name} & lt = $ {latitude} & lon = $ {losition} & dev = 0`Penurl (URL, IDENTITY)
Third, other platforms open maps

Other platforms use the application built-in map to view location using the Application Built-in map viewing location using the UNI.OpenLocation (Object) method.

Uni.openLocation ({Latitude: Latitude, longitude: longitude, name: name, fail: () => {UNI.SHOWMODAL ({Content: ‘Open map failed , Please heavy ‘})},})
Update log


Supports BD-09 (Baidu Coordinate), GCJ-02 (Gaude, Tencent), WGS-84 (GPS Coordinate) coordinate system.
The first release, support the jump third party map and locate the specified coordinates.

Baidu Map URI API
Gao De Map URI API

Uni-App HTML5 + API
The above is All the content of this article, I hope to help everyone, I hope everyone will support Tumi Cloud.
© Copyright Notice
Just support it if you like
comment Grab the couch

Please log in to comment