Support

Account

Home Forums Front-end Issues Google Maps shows only string

Solved

Google Maps shows only string

  • Hi,

    i really apologize for bothering u with this stupid questiong but i dont come along by myself.

    on http://x-virus.org/spielorte/oberfranken/bamberg/memmelsdorf/schloss-seehof

    we are trying to get the google maps custom field working.

    In the Backend it works perfect with all features (Drag/Drop, Zoom, Move) but in the front end it shows only the coords.

    Did i forget about something?

  • Hi @Blacksunice

    Please read over the google map field docs to learn what data is returned and how you can create a google map with the data
    http://www.advancedcustomfields.com/resources/field-types/google-map/

    Thanks
    E

  • well i appreciate that u replied to me.

    i grabbed this code:

    and put it between the <head> <-> </head>

    after this i grabbed

    <?php

    $location = get_field(‘location’);

    if( !empty($location) ):
    ?>
    <div class=”acf-map”>
    <div class=”marker” data-lat=”<?php echo $location[‘lat’]; ?>” data-lng=”<?php echo $location[‘lng’]; ?>”></div>
    </div>
    <?php endif; ?>

    and put it in the loop.

    after it i created a field -> google maps with or without a location, but it doesnt render any map. It only shows the string of the location.

    May u call me dump, but i am totally new to WP and Google Apia and ACF. I honor your work and time. I am not a full of load questioneer. Its the only thing whats missing on our website to begin with theming.

    http://x-virus.org/spielorte/oberfranken/bamberg/memmelsdorf/schloss-seehof

  • i brought the

    <?php

    $location = get_field(‘location’);

    if( !empty($location) ):
    ?>
    <div class=”acf-map”>
    <div class=”marker” data-lat=”<?php echo $location[‘lat’]; ?>” data-lng=”<?php echo $location[‘lng’]; ?>”></div>
    </div>
    <?php endif; ?>

    outside the loop.

    Now it shows an empty field width the height of the acf css

  • Hi @Blacksunice

    In the future, please don’t dump huge block of code like you have. This doesn’t help solve the issue and a simple “I have used the exact code from the above tutorial” would have been suffice.

    Firstly, have you debuged the PHP code to confirm that the data is loading correctly?

    You can debug like so:

    
    <?php 
    
    $location = get_field(‘location’);
    
    echo '<pre>';
    	print_r($location);
    echo '</pre>';
    die; ?>
    

    What data do you get?

    Also, can you confirm that your field name is called ‘location’? Or have you left this the same as the documentation?

    Also, what do you mean, “you have brought it outside the loop”? Please remember that ACF loads data from a post. Similar to the_title / the_content, the acf functions such as get_field need to be used WITHIN the post loop.

    Thanks
    E

  • Thanks for answering 🙂

    I am really sorry about my wall-posting

    What data do you get?

    Array
    (
    [address] => Memmelsdorf, Deutschland
    [lat] => 49.9312092
    [lng] => 10.958558400000015
    )

  • Hi @Blacksunice

    Thanks for the print_r info. As you can see, the get_field function is returning an array of data including the address, lat and lng values. This is exactly as the documentation describes.

    Does this help you to understand where the issue is? We can see that the issue is not with ACF loading data. The issue is with the code you are using to render the map.

    Can you please debug your code line by line to find out why the map is not being created correctly?

    Thanks
    E

  • Safari shows me one error:

    ReferenceError: Can’t find variable: jQuery

    its the last line of your example code

    I dont know what it means

  • finally solved it by a damn mistake

    <script src=”https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=true”></script&gt;

    first it was set to false

    now its perfectly working.

    thanks for your time

  • Thanks Blacksunice for posting your solution, this solved my issue too!

    Edit: Actually I just realised that I had a pin, but becuase map is not centered, I couldn’t see it. what a mess.

Viewing 10 posts - 1 through 10 (of 10 total)

The topic ‘Google Maps shows only string’ is closed to new replies.