About JS connect the German map API, and coordinate shift coordinate transformation

Source: Internet
Author: User
Tags dname

First of all, my own question:

What I do is mixed development, which is the inner shell of the native H5;

Project requirements: Replace the original Baidu map with the Cheng Gaode map.

Problems encountered:

1.h5 Open the Gao de map app, but this H5 page changes into a map and can not return, all rely on physical keys, but Apple where there is a physical key back.

2. Coordinate offset, the end position is Baidu coordinates.

Start telling me the question:

At first I think since it is H5 should take the JS version, the official website portal http://lbs.amap.com/api/javascript-api/summary/

Later I feel that can not write in the inside but also is the web, wrote the URI version, the official website portal http://lbs.amap.com/api/uri-api/summary/

Later consulted the work order, found the right entrance, the delivery door http://lbs.amap.com/api/amap-mobile/summary/

Don't taunt me, Dad used to be a native Android, continue.

This is just plug in the JS, and then first stitching the URI, casually send a bit, the specific code is as follows.

LGMapHelper.prototype.naviURI =function(Fromlat,fromlng,fromname,tolat,tolng,toname,isios) {varIosuri= ' iosamap://path?sourceapplication=applicationname&sid=bgvis1&slat= ' +fromLat+ ' &lon= ' +FROMLNG+ ' &sname= ' +fromname+ ' &did=bgvis2&dlat= ' +tolat+ ' &dlon= ' +tolng+ ' &dname= ' +toName+ ' &dev=0 &t=0 '; varAndroiduri= ' amapuri://route/plan/?sid=bgvis1&slat= ' +fromlat+ ' &lon= ' +FROMLNG+ ' &sname= ' +fromname+ ' &did=bgvis2&dlat= ' +tolat+ ' &dlon= ' +tolng+ ' &dname= ' +toName+ ' &dev=0 &t=0 '; varprotocol = Isios?Iosuri:androiduri; Window.location.href=Protocol; //location.href (' baidumap://map/direction?origin= ' + from + ' &destination= ' + to + ' &mode=driving&src= Webapp.navi.yourCompanyName.yourAppName ');        //return ' baidumap://map/direction?origin= ' + from + ' &destination= ' + to + ' &mode=driving&src= Webapp.navi.yourCompanyName.yourAppName '};

Why should you judge it because it is a mix of developing a set of code for two mobile end use.

The above will be able to adjust the high-German app, and this page does not change.

Coordinate offset: There is no pit, only one key, is error/userkey_plat_nomatch this error.

Give the portal a http://lbs.amap.com/api/javascript-api/reference/lnglat-to-address first.

The wording is:

Amap.convertfrom (x+ "," +y, "" Baidu"                    ,function(status,result)                        {if( status== "complete") {                            tolng=result.locations[0]. N;                            Tolat=result.locations[0]. Q;                            Transform=true;                                                    } Else {                            Console.log (status+ "/" +result);                            Alert ("Get location failed, retry");}                    );

Then the road to the pit is:

First to the portal Http://lbs.amap.com/dev/key/app

The rest is the JS reference when you replace your previous key with the newly created one.

<script type= "Text/javascript" src= "http://webapi.amap.com/maps?v=1.4.0&key= your Key" ></script>

Of course, if you do not report this error error/userkey_plat_nomatch, do not need to change the crab crab.

Well, that's the first step I've just learned about H5 's pit-stepping. \ (^o^)/~

About JS connect the German map API, and coordinate shift coordinate transformation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.