Using the Baidu Map API to achieve according to address query latitude and longitude degree _javascript skills

Source: Internet
Author: User

Copy Code code as follows:

<title> latitude and longitude according to the address of the query </title>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<script type= "Text/javascript" src= "http://api.map.baidu.com/api?v=1.3 "></script>
<body style= "background: #CBE1FF" >
<div style= "Width:730px;margin:auto;" >
To query the address: <input id= "Text_" type= "text" value= "Xuzhou ancient Peng Square" style= "margin-right:100px;" />
Query results (latitude and longitude): <input id= "Result_" type= "text"/>
<input type= "button" value= "Query" onclick= "Searchbystationname ();" />
<div id= "Container"
Style= "Position:absolute;
margin-top:30px;
width:730px;
height:590px;
top:50;
border:1px solid Gray;
Overflow:hidden; " >
</div>
</div>
</body>
<script type= "Text/javascript" >
var map = new Bmap.map ("container");
Map.centerandzoom ("Xuzhou", 12);
Map.enablescrollwheelzoom (); Enable wheel zoom out, default disabled
Map.enablecontinuouszoom (); Enable map inertia drag, default disabled
Map.addcontrol (New Bmap.navigationcontrol ()); Add default zoom translation control
Map.addcontrol (New Bmap.overviewmapcontrol ()); Add default thumbnail map control
Map.addcontrol (New Bmap.overviewmapcontrol ({isopen:true, anchor:bmap_anchor_bottom_right})); Lower right corner, open
var localsearch = new Bmap.localsearch (map);
Localsearch.enableautoviewport (); Allow the form size to be automatically adjusted
function Searchbystationname () {
Map.clearoverlays ()//Empty the original callout
var keyword = document.getElementById ("Text_"). Value;
Localsearch.setsearchcompletecallback (function (SearchResult) {
var poi = searchresult.getpoi (0);
document.getElementById ("Result_"). Value = Poi.point.lng + "," + Poi.point.lat;
Map.centerandzoom (Poi.point, 13);
var marker = new Bmap.marker (new Bmap.point (POI.POINT.LNG, Poi.point.lat)); Create a callout that corresponds to the latitude and longitude of the place to be queried
Map.addoverlay (marker);
var content = document.getElementById ("Text_"). Value + "<br/><br/> Longitude:" + poi.point.lng + "<br/> Latitude:" + P Oi.point.lat;
var Infowindow = new Bmap.infowindow ("<p style= ' font-size:14px; ') > "+ content +" </p> ");
Marker.addeventlistener ("click", Function () {This.openinfowindow (Infowindow);});
Marker.setanimation (bmap_animation_bounce); Bouncing animations
});
Localsearch.search (keyword);
}
</script>

The above is the entire content of the code, small partners can be used directly in the project Oh, do not tell me thank you, please call me Lei Feng Big ~

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.