Skip to main content

Create dynamic map in wordpress or php accoding every user,s address

Create dynamic map in wordpress or php accoding every user,s address

<?php
$address = "Mavviya Nagar Jaipur";
$address = str_replace(" ", "+", $address);
$json = file_get_contents("http://maps.google.com/maps/api/geocode/json?address=$address&sensor=false");
$json = json_decode($json);
$lat = $json->{'results'}[0]->{'geometry'}->{'location'}->{'lat'};
$long = $json->{'results'}[0]->{'geometry'}->{'location'}->{'lng'};

$aLocation = array("title" => 'title',"content" => 'Content',"lat" => $lat,"lon" => $long);
$aLocation = json_encode($aLocation);

?>
<div id="map" style="width:500px;height:400px;"></div>
<script>
var aLocation = <?php echo $aLocation; ?>;
function initMap() {
    myLatLng = {lat: aLocation['lat'], lng: aLocation['lon']};
    var title = aLocation['title'];
    var content = aLocation['content'];
    map = new google.maps.Map(document.getElementById('map'), {
    zoom: 8,
    scrollwheel:  false,
    center: myLatLng
    });
   
    var infowindow = new google.maps.InfoWindow()
    var marker = new google.maps.Marker({ 
        map: map, title: title , position: myLatLng 
    });
    google.maps.event.addListener(marker,'click', (function(marker,content,infowindow){
    return function() {
    infowindow.setContent(content);
    infowindow.open(map,marker);
    };
    })(marker,content,infowindow));
   
}
</script>
<script async defer src="https://maps.google.com/maps/api/js?sensor=false&callback=initMap"></script>

Comments

Popular posts from this blog

High light Search Result In Wordpress

High light Search Result In Wordpress add this function in your themes function.php function highlight_results ( $ text ) {      if ( is_search ( ) ) { $ keys = implode ( '|' , explode ( ' ' , get_search_query ( ) ) ) ; $ text = preg_replace ( '/(' . $ keys . ')/iu' , '<span class="search-highlight">\0</span>' , $ text ) ;      }      return $ text ; } add_filter ( 'the_content' , 'highlight_results' ) ; add_filter ( 'the_excerpt' , 'highlight_results' ) ; add_filter ( 'the_title' , 'highlight_results' ) ;   function highlight_results_css ( ) { ? > <style> .search-highlight { background-color : #FF0 ; font-weight : bold ; } </style> < ? php } add_action ( 'wp_head' , 'highlight_results_css' ) ;

Redirect In contact form 7

add_action( 'wp_footer' , 'redirect_cf7' ); function redirect_cf7() { ?> < script type = "text/javascript" > document.addEventListener( 'wpcf7mailsent' , function ( event ) { if ( '1377' == event.detail.contactFormId ) { // Sends sumissions on form 947 to the first thank you page location = 'https://www.panelesyceldassolares.com/regreso' ; } else { // Sends submissions on all unaccounted for forms to the third thank you page location = 'https://www.panelesyceldassolares.com/regreso-2/' ; } }, false ); </ script > <?php }

Get Single Product By ID in Opencart

<?php if(!empty($_POST["country_id"])) {     $query ="SELECT * FROM oc_product WHERE product_id = '" . $_POST["country_id"] . "'";     $results = $this->db->query($query);   $query2 ="SELECT * FROM oc_product_description WHERE product_id = '" . $_POST["country_id"] . "'";   $results2 = $this->db->query($query2);   $rowresults2 = $results2->row;   $rowresults = $results->row;   $name1 = $rowresults['model'];   $name2 = $rowresults2['name'];   $name3 = $rowresults['price'];   $name4 = 'Exe.' ?>