Js calls Baidu map and calls Baidu map's search function, js search function
How js calls Baidu Map
The Code is as follows:
<! DOCTYPE html>
Js calls Baidu map search
Reference Baidu js Api
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=xxxxxxxxxxxx"></script>
Create an address Parser:
Var localSearch = null; // query parameter var options = {// intelligent search onSearchComplete: function (results) {// query result status code if (localSearch. getStatus () = BMAP_STATUS_SUCCESS) {var s = convertMapSearch (results); // process the result model. locationAddress (s); // assign the result data to the knockout object array (which can be replaced by other array objects) }}; localSearch = new BMap. localSearch ("city", options );
Combined with the textInput binding method of knockout and the subscribe attribute of the object, the real-time query of input box changes is realized.
// Bind <input id = "txtAddress" type = "text" placeholder = "Enter the dining address" data-bind = "textInput: addressInput "/> // when the subscribe attribute changes, run the address query sf. addressInput. subscribe (function (val) {var addr = $. trim (val); if (addr = "") {return;} localSearch. search (addr );});
The above is a small part of the Helper's house. js calls Baidu map and calls Baidu map's search function.