Home > Backend Development > PHP Tutorial > Baidu Map API application to obtain the user's specific location_PHP tutorial

Baidu Map API application to obtain the user's specific location_PHP tutorial

WBOY
Release: 2016-07-13 10:28:36
Original
1047 people have browsed it

About the function: The user clicks on the location on the map to draw points on the map, and then saves the obtained geographical location to the address column on the map.

Baidu Map API application to obtain the user's specific location_PHP tutorial

Mainly the use of Baidu Map API

Copy code The code is as follows:

var map = new BMap.Map("allmap"); //Instantiate one Map object
var point = new BMap.Point(116.331398,39.897445); //Set the location of the map center
map.centerAndZoom(point,12); //Set the visual layer of the map element

map.enableScrollWheelZoom(); //Enable scroll wheel zooming, disabled by default
map.enableContinuousZoom(); //Enable map inertial drag, disabled by default

function myFun(result){
var cityName = result.name;
map.setCenter(cityName);

}
var myCity = new BMap.LocalCity();
myCity.get(myFun);

i=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 marker
map.addOverlay(marker);
marker.enableDragging(); // Can be dragged

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;

//Drawing
var label = new BMap.Label(address,{offset: new BMap.Size(20,-10)});
marker.setLabel(label);
});

i=1;
}

} );

The above code is basically the DOME provided by Baidu. I just made some simple combinations. . Ashamed

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/781413.htmlTechArticleAbout the function: The user clicks on the location on the map to draw points on the map, and then transfers the obtained information to The geographical location is saved to the address column above the map. Mainly...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template