Js calls Baidu map and calls Baidu map's search function, js search function

Source: Internet
Author: User

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.

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.