How to add Google location information and Google location information to a website

Source: Internet
Author: User

How to add Google location information and Google location information to a website

We can easily use HTML5 navigation objects to obtain the current location. Follow these steps to obtain details about the city/country.

Includes the jQuery Library

Copy the content to the clipboard using JavaScript Code
  1. <Script type = "text/javascript" src = "jquery. js"> </script>
  2. JQuery (function (){
  3. // Call navigator object to get latitude and logtitute
  4. If (navigator. geolocation ){
  5. // Getting current latitude and longtitude
  6. Navigator. geolocation. getCurrentPosition (function (position ){
  7. // Get location details based on latitude and longtitude from Google
  8. Var jsonUrl = "https://maps.googleapis.com/maps/api/geocode/json? Latlng = "+ position. coords. latitude +", "+ position. coords. longpolling
  9. JQuery. getJSON (jsonUrl, function (data ){
  10. Var results = data. results [0];
  11. Console.info (results); // check firebug
  12. Alert (results. address_components [5]. long_name); // City
  13. Alert (results. address_components [6]. long_name); // State
  14. Alert (results. address_components [7]. long_name); // Country
  15. },
  16. Function (){
  17. Alert ('failed' to get Location Details ...');
  18. });
  19. Return false;
  20. });
  21. }});

In this article, how to add Google location information on the website is all the content shared by Alibaba Cloud. I hope you can give us a reference and support for the customer's home.

Address: http://www.cnblogs.com/mivi/archive/2016/04/16/5398183.html

Related Article

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.