Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to write the code of Baidu map API application to get the specific location of the user

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report