WeChat enterprise ID development: WeChat attendance Baidu map location 2, attendance Map

Source: Internet
Author: User

Enterprise ID development: Attendance Baidu map location 2, attendance Map

 Using the method in the Baidu map location of attendance, you can locate a specific location in a province, a city, a certain District, a certain road number, it always makes people feel that the display is not very friendly. If it is displayed directly, the software park, is it better for a technology park or something like that? So I checked the documents related to Baidu map, which is actually quite simple. Baidu provides nearby functions and address resolution functions.

For example, I used the Geocoder Service to achieve the desired effect.

Core code:

Var map = new BMap. map ("allmap"); var circle = new BMap. geolocation (); circle. getCurrentPosition (locationResult); // map. addOverlay (circle); var tempGeocoder = new BMap. geocoder (); function locationResult (geolocationResult) {var Status = this. getStatus () if (Status = 0) // the query is successful. Corresponding value "0 ". {$ ("# Lng "). val (geolocationResult. point. lng); $ ("# lat "). val (geolocationResult. point. lat); var address = geolocationResult. address; $ ("# city "). val (address. city); $ ("# district "). val (address. district); $ ("# street "). val (address. street); var text = ""; if (address. province! = Address. city) {text + = address. province;} text + = address. city + address. district + address. street + address. street_number; tempGeocoder. getLocation (geolocationResult. point, locationResultcallback, {poiRadius: 500, numPois: 5}); // $ ("# province "). val (address. province); $ ("# address "). val (text);} else {alert ("failed Locating Error Code" + Status)} function locationResultcallback (GeocoderResult) {var yyy = G EocoderResult. surroundingPois; if (GeocoderResult. surroundingPois. length> 0) {var address2 = GeocoderResult. surroundingPois [0]. title; if (address2) {var text = ""; var province = $ ("# province "). val (); var city = $ ("# city "). val (); if (province! = City) {text + = province;} text + = city; $ ("# address"). val (text + address2 );}}}

Effect:


This is better than the West Three Ring Road in Yanta district, Xi'an City, Shaanxi province.


Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Related Article

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.