• Our agency provides a directory of resources (i.e., shelters and foodshelves) around the state for our clients. Each resource is recorded as a post in a unique category, and each resource has custom fields called “address”, “city”, “state”, and “zip”.

    We would like to create a Google map that automatically populates the map by pulling the address info from the resource posts.

    Of the Gmap plugins available, it seemed like the Phoogle Maps plugin would be easiest to modify for this purpose (http://www.chrisandabigail.com/).

    This plugin relies on php execution within posts, and we got it to work by manually adding addresses in this format:

    <?php addAddress("122 Main St, City, State, 54321"); showMap(); ?>

    It seems like we should be able to pull in the addesses from the post custom fields, so that we won’t have to update the map every time we add a resource post. We installed the Get Custom Fields plugin from CF to assist.

    Here’s the statement we came up with thus far:

    < ?php $my_query = new WP_Query('cat=6'); ?>

    < ?php while ($my_query->have_posts()) : $my_query->the_post(); ?>

    addAddress("< ?php echo c2c_get_custom('address'); ?>, < ?php echo c2c_get_custom('city'); ?>, < ?php echo c2c_get_custom('state'); ?>, < ?php echo c2c_get_custom('zip'); ?> " ,"< ?php the_title(); ?>");

    < ?php endwhile; ?>

    showMap();

    This will print out the [ addAddress(“122 Main St, City, State, 54321”); showMap(); ], but it won’t execute the “addAddress” and “showMap” functions.

    Any ideas on how to wrap the statment we’ve written thus far with another php statment to trigger the map?

    Thanks in advance for any suggestions!

Viewing 13 replies - 1 through 13 (of 13 total)
  • jmanfivek

    (@jmanfivek)

    I’m having the exact same problem, except that I’m not trying to trigger the “addAddress” function with a string of meta values but simply my post’s title which is always in the format of “City, State”.

    From what I can tell, the plugin looks like it calculates the geo coordinates using this site: http://api.local.yahoo.com/MapsService/V1/geocode?appid=YahooDemo&location=

    And that site has no problems when I manually type in “City, State”.

    For some reason Phoogle isn’t passing along the correct addAddress info. It must have something to do with the code inside the addAddress function but I’m not a coder so I have no idea. πŸ™

    Thread Starter LK

    (@lk)

    you’ll need to make one change to the plugin file that wasn’t in the instructions.

    go to yahoo and get your own appid for the Maps Service api for your site (it’s free), and then replace “YahooDemo” with your api in that string.

    its my first time using this, do you have some insturction on how to get it working with yahoo ? I don’t see anywhere like on google to get a code to use.

    Thread Starter LK

    (@lk)

    I’m not the author of this plugin, but I’ve found it very helpful for clients who prefer to add street addresses instead of geocoding coordinates.

    Just so we’re on the same page: this plugin only uses Yahoo for translating street addresses to geocode coordinates, and then the plugin passes the geocode coordinates to Google Maps. As far as I can tell, the plugin only shows maps in Google Maps — not Yahoo Maps.

    To get the Yahoo geocoding function working:

    Go to http://api.search.yahoo.com/webservices/register_application and log in (if you don’t already have a Yahoo account, create one). You’ll be taken to a screen prompting you to choose an Application ID. I usually use my site name. Then, go back to the phoogle plugin file and replace “YahooDemo” with your new Applicatio ID. That’s it.

    Thanks LK I updated that part and I think it is working. I was getting an error about yahoo maps not working.

    Im using Exec-PHP 3.0, Phoogle Maps 2.0, WordPress 2.0.4 on Goddays free hosting. Would it have something to do with the hosting ?

    I get this error

    Parse error: parse error, unexpected T_STRING in /home/content/M/i/n/Miniphoto/html/wordpress/wp-content/plugins/exec-php/exec-php.php(75) : eval()’d code on line 1

    from this post

    <?php addAddress(β€œ301 Main St., Baton Rouge, LA 70801β€³);showMap(); ?>

    Thread Starter LK

    (@lk)

    Did you copy that line directly from the plugin page to your write screen? I seem to remember that the plugin page had stylized quotation marks that don’t play well. Try deleting and retyping the two quotation marks.

    You want them to look like this: “

    And not like these: β€œ or β€³

    Thanks again for your help, thats solves that problem, I don’t get any errors now.

    But all I get is a blank post now. any ideas on what I’m doing wrong now ?

    Thread Starter LK

    (@lk)

    Could you share a link please?

    Thread Starter LK

    (@lk)

    It looks like it knows that there should be a map there, it just doesn’t get created.

    The error message regarding file_get_contents in “Test 3” would suggest that your host is running an older version of PHP. Or, it could just be that you only had a street address and no city/state/zip address in the addAddress line for “Test 3”.

    Could you please create a new post called “Test LK”, and use the example addAddress line from the plugin page (the one you quoted above)?

    Also, could you find out what version of PHP your host is running? And, are you running any other plugins?

    Not sure how to tell but I found a site that said to put ‘ <? phpinfo();?> ‘ as php.info on the site and go to it and it says 4.3.11 at the top

    These are the plugins that I have activated
    Exec-PHP 3.0
    Phoogle Maps 2.0
    List Manager 1.9
    Event Calendar 3.1._rc3

    I was getting the same effect when i only had the first 2 installed. I have been reading that godaddy has caused problems with wordpress and things but The free hosting came with the .com so I thought I would try it.

    thanks again for all your help

    Thread Starter LK

    (@lk)

    The plugin should automatically put some code into your footer to enable the Google map. It doesn’t look like your pages have this code.

    Could you check to see if your theme files (usually footer.php) to see if it has this line:

    <?php wp_footer(); ?>

    If not, add it at the bottom right above the </html> line.

    Thanks … the theme I had didn’t have that so I went back to the default and it worked but that wasn’t included so I added

    <?php wp_footer(); ?>
    </html>

    to the end of the them footer and it works.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Coding question for dynamic Gmap’ is closed to new replies.