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.