Adsense Ad

Thursday, 21 November 2019

Convert google map into image using longitude and latitude

Google Map Image based on Address

<img src="https://maps.googleapis.com/maps/api/staticmap?center=Brooklyn+Bridge,New+York,NY&zoom=12&size=600x400"/>

Google Map Image based on Latitude & Longitude

<img src="https://maps.googleapis.com/maps/api/staticmap?center=40.714728,-73.998672&zoom=12&size=600x400"/>

Google Map Image with Marker based on Latitude & Longitude

<img src="https://maps.googleapis.com/maps/api/staticmap?center=40.714728,-73.998672&markers=color:red%7Clabel:C%7C40.718217,-73.998284&zoom=12&size=600x400"/>

Save Google Map as an Image using PHP

<?php
    $src 'https://maps.googleapis.com/maps/api/staticmap?center=40.714728,-73.998672&markers=color:red%7Clabel:C%7C40.718217,-73.998284&zoom=12&size=600x400';
    $time time();
    $desFolder 'images/';
    $imageName 'google-map_'.$time.'.PNG';
    $imagePath $desFolder.$imageName;
    file_put_contents($imagePath,file_get_contents($src));?><img src="<?php echo $imagePath; ?>"/>

Specify a Google API Key

Use key parameter with the URL of Google Static Maps API for specifying a Google API Key.
https://maps.googleapis.com/maps/api/staticmap?center=40.714728,-73.998672&zoom=12&size=600x400&key=YOUR_API_KEY






No comments: