Working with Google maps

Google maps with geolocation for tracking the user location and get content accordingly.

How to get the country name using latitude & longitude?

 

$deal_lat=-37.759628;
$deal_long=144.929291;
$geocode=file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?latlng='.$deal_lat.','.$deal_long.'&sensor=false');

$output= json_decode($geocode);

for($j=0;$jresults[0]->address_components);$j++){
           $cn=array($output->results[0]->address_components[$j]->types[0]);
           if(in_array("country", $cn))
           {
            $country= $output->results[0]->address_components[$j]->long_name;
           }
 }
echo $country;

How to get current location with movable marker and get the value in a text field?

<code>

<div id="map"></div>
    <script>
      function initMap() {
          var myLatLng = {lat: -37.706291, lng: 144.91165};

        var mapDiv = document.getElementById('map');
        
        var map = new google.maps.Map(mapDiv, {
          center: myLatLng,
          zoom: 14
        });

        var marker = new google.maps.Marker({
            position:myLatLng,
            draggable:true,
            map:map,

        });

        google.maps.event.addListener(marker, 'dragend', function (event) {
            document.getElementById("latbox").value = this.getPosition().lat();
            document.getElementById("lngbox").value = this.getPosition().lng();
        });

        
      }
    </script>
    <script src="https://maps.googleapis.com/maps/api/js?callback=initMap"
        async defer></script>


    <div id="latbox"><input type="text" id="lngbox" /></div>

</code>



About me

I'm Subash Thapa (web developer, freelancer, designer).

Web development has been my passion from the day I started using computer. I can help you from the first stage of website i.e designing, programming(developing) till the last stage or deployment, including domain name registration and hosting.

I would love to get engaged in any type of website to design, develop or maintenance.