1function getReverseGeocodingData(lat, lng) {
2 var latlng = new google.maps.LatLng(lat, lng);
3 // This is making the Geocode request
4 var geocoder = new google.maps.Geocoder();
5 geocoder.geocode({ 'latLng': latlng }, (results, status) =>{
6 if (status !== google.maps.GeocoderStatus.OK) {
7 alert(status);
8 }
9 // This is checking to see if the Geoeode Status is OK before proceeding
10 if (status == google.maps.GeocoderStatus.OK) {
11 console.log(results);
12 var address = (results[0].formatted_address);
13 }
14 });
15}
1<script src="https://cdn.jsdelivr.net/gh/bigdatacloudapi/js-reverse-geocode-client@latest/bigdatacloud_reverse_geocode.min.js" type="text/javascript"></script>
2<script type="text/javascript">
3
4 /* Initialise Reverse Geocode API Client */
5 var reverseGeocoder=new BDCReverseGeocode();
6
7 /* Get the current user's location information, based on the coordinates provided by their browser */
8 /* Fetching coordinates requires the user to be accessing your page over HTTPS and to allow the location prompt. */
9 reverseGeocoder.getClientLocation(function(result) {
10 console.log(result);
11 });
12
13 /* Get the administrative location information using a set of known coordinates */
14 reverseGeocoder.getClientLocation({
15 latitude: -33.8688,
16 longitude: 151.2093,
17 },function(result) {
18 console.log(result);
19 });
20
21 /* You can also set the locality language as needed */
22 reverseGeocoder.localityLanguage='es';
23
24 /* Request the current user's coordinates (requires HTTPS and acceptance of prompt) */
25 reverseGeocoder.getClientCoordinates(function(result) {
26 console.log(result);
27 });
28
29</script>