PhoneGap geolocation combine Baidu Map API to get geolocation API

Source: Internet
Author: User

First, the use of Baidu Map API

1, Address: http://developer.baidu.com/map/

2. Get the demo of anti-address resolution in JS Demo

    

3, modify the demo key, to create the application can create the key, and then copy the key to this page

4. Use PhoneGap geolocation to obtain the latitude and longitude assigned to point

<!DOCTYPE HTML> <HTML><Head><MetaCharSet= "Utf-8"><title>Phonegap_device_network_notification01</title><Linkhref=".. /jquery.mobile-1.3.2.css "rel= "stylesheet"type= "Text/css"/><Scriptsrc=".. /jquery.js "type= "Text/javascript"></Script><Scriptsrc=".. /jquery.mobile-1.3.2.js "type= "Text/javascript"></Script><Scriptsrc=".. /cordova.js "type= "Text/javascript"></Script><Scripttype= "Text/javascript"src= "http://api.map.baidu.com/api?v=2.0&ak=17923c0196cbabf7603ea9edabdf787d"></Script><Scripttype= "Text/javascript"CharSet= "Utf-8">    //wait for phonegap to loadDocument.addeventlistener ("Deviceready", Ondeviceready,false); //Load Complete    functionOndeviceready () {navigator.geolocation.getCurrentPosition (onsuccess, onerror,{timeout:100000, Enablehighaccuracy:true }); }      functiononsuccess (position) {varelement=document.getElementById ('geolocation'); varLatitude=Position.coords.latitude;//Latitude        varLongitude=Position.coords.longitude;//Diameter degreegetPosition (longitude,latitude); }    //OnError callback function that receives the Positionerror object containing the specific error message    functionOnError (Error) {alert ('Error code:'    +Error.code+ '\ n' +              'More information:' +Error.message+ '\ n'); }      //get a detailed address based on latitude and longitude    functiongetPosition (longitude,latitude) {//Baidu Map API features        varMap= NewBmap.map ("Map"); var Point= NewBmap.point (longitude,latitude); Map.centerandzoom (Point, A); varGC= NewBmap.geocoder (); Gc.getlocation (Point,function(RS) {varAddcomp=rs.addresscomponents; Alert (addcomp.province+ ", " +addcomp.city+ ", " +addcomp.district+ ", " +Addcomp.street+ ", " +addcomp.streetnumber);                      }); }        </Script></Head> <styletype= "Text/css">#map{width:100%;Height:200px;}</style><Body><DivData-role= "page">        <DivData-role= "header">            <H1>PhoneGap100 Combat</H1>        </Div>        <DivData-role= "Content"ID= "Map">                    </Div>                <DivData-role= "Footer">            <h4>&nbsp;</h4>        </Div></Div></Body></HTML>

PhoneGap geolocation combine Baidu Map API to get geolocation API

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.