JQuery obtains latitude and longitude through the address demo, jquery latitude and longitude

Source: Internet
Author: User

JQuery obtains latitude and longitude through the address demo, jquery latitude and longitude

Before getting started, you must first log on to the Baidu map API console to apply for a key ak.

1. login Baidu map open platform http://lbsyun.baidu.com

Register an account and complete the information. Click "API console" in the upper-right corner of the website and click "create application.

Application Type: "server", IP whitelist: 0.0.0.0/0

Click Submit. An access application (AK) is generated ).

 

2. Compile the interface.
<! DOCTYPE html> <Br> point: <input type = "text" name = "point" id = "point" style = "width: 30% "readonly> <button type =" button "id =" open "> getPoint </button> </body> 3. Core Methods
<Script type = "text/javascript"> document. getElementById ('open '). onclick = function () {var addressStr = $ ("# address "). val (); if (addressStr! = "") {$. Ajax ({url: "http://api.map.baidu.com/geocoder/v2/", data: {"address": addressStr, "output": "json", "ak": "ak you just applied "}, type: "post", dataType: 'jsonp', success: function (data) {var lng = data. result. location. lng; var lat = data. result. location. lat; $ ("# point "). val (lng + "," + lat) ;}}) ;}else {alert ("addres is not null! ") ;}}</Script>
4. effect display:

If no address is entered, the following message is displayed:

 

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.