Baidu map implementation on secure pages

2019-05-20 17:30发布

问题:

We are making our store locator pages secure for China site but the issue is Baidu URL https://api.map.baidu.com/api?v=1.4&ak=xxxxxx automatically redirect itself to http url.

When I hit above URL 'https://api.map.baidu.com/..' in browser it shows following code -

(function(){ window.BMap_loadScriptTime = (new Date).getTime();      
document.write('<script type="text/javascript"
src="http://api.map.baidu.com/getscript?
v=1.4&ak=xxxx&services=&t=20150522093217"></script>');})();

Using this URL directly 'http://api.map.baidu.com/getscript?v=1.4&ak=xxxx&services=&t=20150522093217' then it is accessible over https but then other issues start coming -

Blocked loading mixed active content "http://api.map.baidu.com/getmodules?v=1.4&mod=map,scommon,mapclick,oppc,navictrl,control" Blocked loading mixed active content "http://api.map.baidu.com/getmodules?v=1.4&mod=marker,tile"

Till now I found one blog for this - Source:https://groups.google.com/forum/#!topic/angular/mkN2-nuMSfY mentioning that there is separate API url to implement API over https something like- https://sapi.map.baidu.com/ but this solution not working and not able to find any documentation related to this on Baidu site.

If somebody has implemented Baidu over https please help on this.

回答1:

So basically Baidu map version 1.4 does not support secure URLs.So updated the code to include version 2.0

https://api.map.baidu.com/api?v=2.0&ak=xxxxxx&s=1

Other changes I have made

  • Parameter 's=1' is appended to the API url.
  • Put Server IPs in white-listed Ips for the browser key
  • All iframes, scripts and images urls must not start with http.