How to write the code of Baidu map API application to get the specific location of the user
This article mainly explains "how to write Baidu Map API application to get the user's specific location code", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "how to write Baidu map API application to get the user's specific location code"!
Approximate function: users click on the location on the map, draw points on the map, and then save the geographical location to the address column on the map.
Mainly the use of Baidu Map API
The copy code is as follows:
Var map = new BMap.Map ("allmap"); / / instantiate a map object
Var point = new BMap.Point (116.331398 minute 39.897445); / / set the location of the map center
Map.centerAndZoom (point,12); / / sets the visual layer of map elements
Map.enableScrollWheelZoom (); / / enable wheel zoom in and out. Default is disabled.
Map.enableContinuousZoom (); / / enables map inertia drag and drop, which is disabled by default
Function myFun (result) {
Var cityName = result.name
Map.setCenter (cityName)
}
Var myCity = new BMap.LocalCity ()
MyCity.get (myFun)
ITunes 0
/ / Click to get the coordinates
Map.addEventListener ("click", function (e) {
If (I = = 0)
{
/ / Storage latitude and longitude
Lng = e.point.lng
Lat = e.point.lat
/ / draw points on the map
Var marker = new BMap.Marker (new BMap.Point (lng,lat)); / / create a dimension
Map.addOverlay (marker)
Marker.enableDragging (); / / draggable
Var gc = new BMap.Geocoder ()
/ / get the data address of the address
Var pt = e.point
Gc.getLocation (pt, function (rs) {
Var addComp = rs.addressComponents
Address = addComp.province + addComp.city + addComp.district + addComp.street + addComp.streetNumber
/ / draw a picture
Var label = new BMap.Label (address, {offset:new BMap.Size (20lemmer10)})
Marker.setLabel (label)
});
ITunes 1
}
});
At this point, I believe you have a deeper understanding of "how to write Baidu Map API application to get the user's specific location code", you might as well to actually operate it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!