Address Geocoder WordPress Plugin


A simple WordPress plugin for saving location data with Posts and Pages. Conveniently converts addresses to lat/lng from the Edit screen.

Storing addresses as lat/lng (rather than geocoding each time a user requests a page) decreases load time. This plug-in makes it easy for content managers to generate lat/lng, which is stored with the post as a custom field that can be accessed as part of the loop.

Uses the Google Maps JavaScript API V.3.

Installation and Usage

  1. Get a copy of the plugin from WordPress.org or Github);
  2. Unzip and upload it to your /plugins directory;
  3. Activate the plugin from the Dashboard;
  4. You should now find a metabox labeled “Geocoder” on your Post and Page Edit screens. Enter an address in the address field (this can be an exact address or the name of a famous place — anything Google will understand);
  5. Press the “Geocode Address” button;
  6. The Lat/Lng field will populate with a lat/lng object and a map will appear in the preview box, with a marker on the location.

Access your data in the loop using the functions get_geocode_latlng() and get_geocode_address(), with the post ID passed as a parameter. Such as:

Lat/Lng:
<?php echo get_geocode_latlng($post->ID); ?>
 
Address:
<?php echo get_geocode_address($post->ID); ?>

That’s it!

Issues and Support

If you need a hand or find a bug, please leave a comment here or, preferably, open a ticket on Github. Thanks!

Posted May 2012

  • Lenorah

    Hello,

    Thank you for your hard work. Il tried to install your plugin but I get an error each time a page loads (admin site) saying that I need to give a value to sensor parameter. I checked the page source and it seems the end of the maps api url is truncated, the query parameters (key and sensor) are not displayed, there is only this : http://maps.googleapis.com/maps/api/js .
    Any clue please?

    • Lenorah

      Thank you for helping me by e-mail Marty. It seems this problem is caused by my theme or plugin, which strips the script urls from their parameters. I’m gonna ask the theme’s developper about it.

  • Alex

    I’ve noticed that when adding a pin with this plugin it will add the pin out in the street and not over the top of the building. Is there a way to get it located in the center of the building?

    • martyspellerberg

      This plugin is a front-end for the Google Maps API. It simply passes the address to Google and receives the lat/lng response. You might find another geocoding service gives you the results you’re looking for, but at this time there are no plans to support them with this plugin.

  • pnoeric

    Hey, nice plugin– thanks for making it!

  • Joe Fisher

    I can get the demo working. When trying it on a site, I copy and modify the index file to make a page template file, and copy the map.js and icons. The posts don’t show the map, only the body information. The main page map doesn’t show the icons. If I add a geocode directly into the map page it shows the location. That means the icon path is OK, right? What should I look for to get it to work?

  • Joe Fisher

    The issue has to do with loading the posts onto that map page created. On my install however, when changing it, it ignores the template made for the map, and simply displays the front page. That shouldn’t be, but that’s what’s happening to me.

  • Joe Fisher

    Sorry this is more of an issue for the integration tutorial and not an issue with the plugin. Since I posted here anyway, I solved (cheated) due to time constraints, by making a new wordpress install with the map and a subdomain called map.mydomain.org and use it only and specifically for the map issue I have. I was not able to figure out how to load the posts into a custom page template which is required for the map to show all the pins. Using the (useless) reading setting of posts to another page just overrides any custom template so it’s useless.

  • Salonglong

    How to get all posts on the map? And displayed in the page, thanks

    • Douglas Haynes

      I downloaded one of my theme templates, added the code renamed and saved the template file, uploaded it to my theme folder with the .js file, then add new page chose the new template.

  • Lộc Đ. Phạm

    I don’t quite understand how to use this plugin. Is it mainly for convenience getting the lat/long from the Edit page? I have a form on my page with the user address, how do I use this to capture the lat/long of the user address inputed?

    • martyspellerberg

      You’re on the right track, it’s for convenience on the Edit screen. When collecting the address, store it in a custom field called “martygeocoderaddress.” (This is possible via Gravity Forms or similar.) And then you can convert that to lat/lng on the Edit screen.

  • goma

    the warning shows when I post something after activating this plugin.
    That is “Maps API in this app is stopped. Key is invalid or not allowed in this site.
    is this because I run wordpress in my local PC?

    • martyspellerberg

      Yeah, Google Maps doesn’t work on localhost.

      • goma

        Thanks a lot, Marty.

      • goma

        are there the way to using your plugin and Google maps on localhost?

        • martyspellerberg

          No, that is not possible.

          • goma

            i see.
            many thanks! (^^

  • Guest

    thanks a lot, marty.

  • davinian

    I’m seeing the same error message – this is on live sites, not localhost.

    “Google has disabled use of the Maps API for this
    application. The provided key is not a valid Google API Key, or it is
    not authorized for the Google Maps Javascript API v3 on this site. If
    you are the owner of this application, you can learn about obtaining a
    valid key here: https://developers.google.com/maps/documentation/javascript/tutorial#api_key

    • davinian

      ok I’ve just generated my own API Key and updated line 67 in address-geocoder.php and everything is working – guessing the plugin has exceeded the 25,000 requests/day limit (must have a lot of people using it, which is good 🙂

      • martyspellerberg

        Great! I’m going to recommend people do this this as a temporary measure, while we get an update prepped and pushed out.

  • Hi,
    I just started to use your WP plugin and I very satisfied with it.
    I have a question. Is it possible to generate multiple meta box? I need to store more the one coordinate.

    Thanks,
    L

  • Serge

    Hi,
    Nice plugin, but when I register a new post type, it doesn’t appear in the options, so I can not exclude it. You should change the loop at line 174.Thkx

  • Kris Bee

    Hi there. I keep getting the following error – InvalidKeyOrUnauthorizedURLMapError – i have created the API keys as per the instructions but whenever I goto the post type which i want to use the plugin with i get that error.

    Have tried Googling but have been unable to find an answer that works. Really hoping you can help!!

    Thanks,

    Kris

  • Cassie

    Hi

    Thanks, this plugin is making my life a whole lot easer, I have a map that needs to spit out a few dozen markers, and geocoding it in my theme was obviously hitting the limit.

    I’m having a problem though, when I use ID); ?> the output is nothing. The other get functions work fine. Any ideas? I assume this is either something I’ve managed to mess up, or an issue with newer versions of wordpress, since the plugin hasn’t been updated in a while.

    Thanks again!

    • Cassie

      Oh my gosh, I missed the echo. How embarrassing. This is what I get for coding on no sleep!

  • Fülig Jimmy

    Hi, I want the geocoder to automatically calculate the values when saving the custom post. Is it possible?
    Thank you

  • Selectiveform

    I would like to know how to auto create the geocoding on save post instead of manually clicking the create button? I intent to use it for user generated post from front end and I don’t want to manually process it for 100’s of post.

This website is hosted by Media Temple. Thanks, guys!