jcadima
10/5/2015 - 8:56 PM

Custom Google Maps, PHP / WP(custom Fields) / Javascript (non-google_API maps)

Custom Google Maps, PHP / WP(custom Fields) / Javascript (non-google_API maps)


REF: http://stackoverflow.com/questions/3807963/how-to-get-longitude-and-latitude-of-any-address
    <?php
     // Get lat and long by address         
        $address = get_field('map') ;  // we are getting an address from a custom field WP
        $prepAddr = str_replace(' ','+',$address);
        $geocode=file_get_contents('http://maps.google.com/maps/api/geocode/json?address='.$prepAddr.'&sensor=false');
        $output= json_decode($geocode);
        $latitude = $output->results[0]->geometry->location->lat;
        $longitude = $output->results[0]->geometry->location->lng;

        echo "LATITUDE: " .  $latitude   . '<br>';
        echo "LONGITUDE: " .   $longitude  . '<br>';

    ?>   
<!--  this will display the map -->
<script type="text/javascript" src="http://www.webestools.com/google_map_gen.js?lati=<?php echo $latitude; ?>&long=<?php echo $longitude; ?>&zoom=13&width=675&height=400&mapType=normal&map_btn_normal=yes&map_btn_satelite=yes&map_btn_mixte=yes&map_small=yes&marqueur=yes&info_bulle="></script><br />
 
 
<!--  Ref for this form: https://css-tricks.com/snippets/html/get-directions-form-google-maps/  
This form will let you enter an address and open a new tab with  directions
-->    
<form action="http://maps.google.com/maps" method="get" target="_blank">
   <label for="saddr">Enter your location</label>
   <input type="text" name="saddr" />
   <input type="hidden" name="daddr" value="<?php  the_field('map') ; ?>" />
   <input type="submit" value="Get directions" />
</form>