Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • You guys are more than welcome!

    Dear LeRedac,
    I am a PHP developer, somewhat new to WP. I tried your code, spiced it up with an if statement to see why it won’t show the map. The field name is: “laama_map”.
    I don’t know where i have got it wrong, but it always executes the else part of the if statement. Thanks for your help in advance!

    Here is my code:

    get_header();
    $postReceivedID='36';
    $foundPost=get_post($postReceivedID);
    global  $foundPost;
    echo  $foundPost->post_title;
    echo   $foundPost->post_content;
    echo   $foundPost->the_date;
    /* $location = get_field('laama_map'); */
    ?>
    <div id="view1" style="background-color:red; height:600px; width:700px; margin-left:300px;">
    <?php
    $location = get_field('laama_map');
    if( ! empty($location) ){
    ?>
    <div id="map" style="width: 100%; height: 350px;"></div>
    <script src='https://maps.googleapis.com/maps/api/js?sensor=false' type='text/javascript'></script>
    
    <script type="text/javascript">
      //<![CDATA[
    	function load() {
    	var lat = <?php echo $location['lat']; ?>;
    	var lng = <?php echo $location['lng']; ?>;
    // coordinates to latLng
    	var latlng = new google.maps.LatLng(lat, lng);
    // map Options
    	var myOptions = {
    	zoom: 9,
    	center: latlng,
    	mapTypeId: google.maps.MapTypeId.ROADMAP
       };
    //draw a map
    	var map = new google.maps.Map(document.getElementById("map"), myOptions);
    	var marker = new google.maps.Marker({
    	position: map.getCenter(),
    	map: map
       });
    }
    // call the function
       load();
    //]]>
    </script>
    <?php
    }
    else { echo "map not found"; }
    ?> 
    
    </div>
    <?php
    
    //Display the footer
    get_footer();
    ?>

    [Moderator Note: Please post code or markup between backticks or use the code button. Or better still – use a pastebin. Your posted code may now have been permanently damaged by the forum’s parser.]

Viewing 2 replies - 1 through 2 (of 2 total)