Blogs

Blogs

Dynamic MAP

You can use this code of map, when you want to create map from your address.

Javascript Code :

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAkZ9cFn9kUTJbkRy4LjwTvGhnv9GWeexs" ></script>
<script type="text/javascript">
    function initialize() {
        var latLng = new google.maps.LatLng(<?php echo $lat; ?>,<?php echo $long; ?>);
        var mapOptions = {
            center: latLng,
            zoom: 12,
            scrollwheel: false,
            disableDoubleClickZoom: true,
        };
        var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

        var marker = new google.maps.Marker({
            position: latLng,
            map: map,
            title: '<?php echo $UserArry['User']['orgemp_name']; ?>'
        });
    }
    google.maps.event.addDomListener(window, 'load', initialize);
</script>

PHP Code :

$add1 = "Adajan";
$cityName = "Surat";
$stateName = "Gujarat";
$countryName = "India";

$add = $add1 . ", " . $cityName . ", " . $stateName . ", " . $countryName . ", ";
$addr = urlencode($add);
$url = "http://maps.google.com/maps/api/geocode/json?address=$addr&sensor=false";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXYPORT, 3128);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
curl_close($ch);
$response_a = json_decode($response);

$lat = $response_a->results[0]->geometry->location->lat;

$long = $response_a->results[0]->geometry->location->lng;