JSFiddle - React, Tailwind, and code Playground

by bizamajig

HTML

<script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>

JavaScript

var region = "";
    var country = "";
$.getScript( '//maps.googleapis.com/maps/api/js?v=3.exp&async=2&libraries=places,geometry&key=AIzaSyDXlwwrHCnEP50L1rFQvrYq9XAzpU_hZvA&callback=showPosition', function(){});
/*
function getLocation()
    {
        if (navigator.geolocation)
          {
              navigator.geolocation.getCurrentPosition(showPosition,noGeolocation);
          } else {
              console.log('nope');
          }
    }
*/
function showPosition(position) {
    var geocoder = new google.maps.Geocoder();
    var latlong = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
    geocoder.geocode({'latLng': latlong}, function(results, status) {

        if (status == google.maps.GeocoderStatus.OK) {
            if (results[0]) {
                for (var i = 0; i < results[0].address_components.length; i++) {
                    var longname = results[0].address_components[i].long_name;
                    var types = results[0].address_components[i].types;

                    for (var typeIdx = 0; typeIdx < types.length; typeIdx++) {
                        if (types[typeIdx] == 'country') {
                            console.log(results[0].address_components[i].long_name);
                            console.log(results[0].address_components[i].short_name);
                        }
                    }
                }
            }
        } 
    });
}
    function noGeolocation()
    {
        console.log('nope2');   
    }

    getLocation();