Google Maps API Development get coordinates and street details

Source: Internet
Author: User
Tags reverse geocoding

Your project has the need to get the coordinates of the current click or to get information about the current street.
Estimate this for the novice, or is more troublesome, because from the official internet to find this is not very easy to find, to look for a long time, good luck may be found in a sudden.

Give yourself a test case. The code is as follows:

<! DOCTYPE html>html, body {height:100%; Margin:0; padding:0; } #map {height:100%; }    </style>functionInitmap () {varMYLATLNG ={lat:39.921323, LNG:116.426239            }; varmarker; varMarkersarray = []; varMap =NewGoogle.maps.Map (document.getElementById (' Map ')), {zoom:12, center:mylatlng}); //----Google Hide----            varIsfirstload=true; //the callback after the map tile loading is completeGoogle.maps.event.addListener (map, ' tilesloaded ',function () {            if(isfirstload) {Hidelogo (); Isfirstload=false;            }               }); functionHidelogo () {$ ("#map. GM-STYLE-CC"). Hide (); $("#map [title= ' Click to view this area on Google maps]"). Hide (); }            //----Google Hide----Map.addlistener (' click ',function(e) {addmarker (e.latlng, map); //get current geographic information based on latitude and longitude                varLatlngdata = E.latlng.lat (). toFixed (6) + ', ' +e.latlng.lng (). toFixed (6); Console.log (Latlngdata) $.ajax ({type:"POST", URL:"Https://maps.googleapis.com/maps/api/geocode/json?latlng=" +latlngdata+ "&location_type=rooftop&result_ Type=street_address&key=aizasyc8ixpngfa7ud-xb0jeqhkedb7j3gbgoie ", Async:true, Success:function(data) {Console.log (data)varsite = latlngdata+ ' <br/> ' +data.results[0].formatted_address; Console.log (site)varInfowindow =NewGoogle.maps.InfoWindow ({content:site}); Infowindow.open (Map,marker); //pop-up message prompt window                    }                });            }); //Add Coordinate Object            functionAddmarker (latlng, map) {if(markersarray.length>0) {markersarray[0].setmap (NULL);                }; Markersarray.shift (marker) marker=NewGoogle.maps.Marker ({position:latlng, map:map});            Markersarray.push (marker); }        }    </script> <script src= "http://libs.baidu.com/jquery/1.9.0/jquery.js" ></script> <script src= " Https://maps.googleapis.com/maps/api/js?key=AIzaSyC8IXpNgfA7uD-Xb0jEqhkEdB7j3gbgOiE&callback=initMap "Async Defer></script></body>$ (window). Load (function(){        //$ ("#map [title= ' Click to view this area on Google Maps ']"). Hide ();        //$ ('. gm-style-cc '). Hide ();    });</script>

注意: Please introduce yourself to the local jquery, because to use the AJAX request, Google's geo-service interface.

The core of the code is the URL of the request:

URL: "https://maps.googleapis.com/maps/api/geocode/json?latlng=" &location_type=ROOFTOP& "+latlngdata+" Result_type=street_address&key=aizasyc8ixpngfa7ud-xb0jeqhkedb7j3gbgoie "

This is a latitude reverse geocoding, the URL has four parameters:,,, and latlng location_type result_type key Detailed concepts and parameters, please refer to the next chapter of the Google Maps API development Geocoding API

Google Maps API Development get coordinates and street details

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.