Baidu Map API positioning current and bus query

Source: Internet
Author: User


This article mainly introduces the Baidu map automatic positioning to the current function, then you can specify the starting location to query the bus.

<! DOCTYPE html><html><head>    <meta http-equiv="Content-type" Content="text/html; Charset=utf-8 " />    <meta name="viewport" content="initial-scale=1.0, User-scalable=no " />    <style type="Text/css">        Body,HTML {width: %;  height: %;  margin:0;  font-family:"Microsoft Jas Black";  font-size:px; }        #l-map{height: +px;  width:%; }        #r-result,#r-result Table{width:%;  Clear:both; }        #routePanel P{float:left;}     </style>    <script type="text/javascript" src=" /API?V=2.0&AK=DDD05FCBA9FEA5B83BF648515E04FC4C "></script>    <script src="Http://"></script>    <title>Multi-end selection of bus transfer query</title></head><body>    <div id="L-map"></div>    <div id="Routepanel">        <p Style="margin-right:10px;" >Starting point:<span><input type="text" id="Start"></input></span></P>        <p>End:<span id="b_pointname1"><input type="text" id="End"></input></span></span>        <button onclick="search ()">Inquire</button>    </div>    <div id="R-result" style="Display:none;" ></div></body></html><script type="Text/javascript">    varMap ("L-map"); Map.centerandzoom (NewBmap.point (116.404,39.915), A); Map.enablescrollwheelzoom ();//Navigate to Current location    varGeolocation =NewBmap.geolocation (); Geolocation.getcurrentposition ( function(r){        if( This. getStatus () = = bmap_status_success) {varmk =NewBmap.marker (R.point);            Map.addoverlay (MK); Map.panto (R.point);//alert (' Your location: ' +r.point.lng+ ', ' ');}Else{Alert (' failed '+ This. GetStatus ()); }},{enablehighaccuracy:true})//About status code    //bmap_status_success retrieved successfully. Corresponds to the value "0".     //bmap_status_city_list City list. Corresponds to the value "1".     //bmap_status_unknown_location location result unknown. Corresponds to the value "2".     //bmap_status_unknown_route navigation results are unknown. Corresponds to the value "3".     //bmap_status_invalid_key illegal keys. Corresponds to the value "4".     //bmap_status_invalid_request illegal request. Corresponds to the value "5".     //bmap_status_permission_denied does not have permissions. Corresponds to the value "6". (added since 1.1)    The //bmap_status_service_unavailable service is not available. Corresponds to the value "7". (added since 1.1)    //bmap_status_timeout Timeout. Corresponds to the value "8". (added since 1.1)    varTransit =NewBmap.transitroute (map, {renderoptions: {map:map, Panel:"R-result"}, Onresultshtmlset: function(){$("#r-result"). Show ()}); function search() {        varStart = $ ("#start"). Val (), End = $ ("#end"). Val (); (Start,end); }</script>
Test results


According to some of Baidu's API, can make their own personalized navigation system, interested friends can be in-depth study. Related to Baidu provided reference: Http://

Baidu Map API positioning current and bus query

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: 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.