Geocode inside a CustomPostType

Home Forums MapPress Support Geocode inside a CustomPostType

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #13712

    Hello Chris,

    I am looking for a solution:
    I create CustomPostTypes with TYPES ( and I publish the content with their VIEW-plugin. Everything is ok.
    In the CPT, I ask for adress data and therefor it would be very easy to have MapPressPro to create the maps automatically. It works fine that way.

    My problem is that I must store the LAT and LONG coordinates as well, because my clients will integrate other maps beside google maps as well (german navigation maps for pedestrians and cyclists,, which works only with LAT and LONG, not with adresses.

    That is wyh I must store the LAT and LONG in dedicated Custom Fields, but I can’t find a way how to offer a nice geocoder to my users who have to create these CustomPostType-pages.
    Is there a way to add a geocoder to a certain CPT and have its results stored in custom fields?

    Or, as a workaround, offer a geocoder in a metabox in the side-position, where the users can click, generate the coordinates and copy them into their customfields-input?

    Maybe I do not see the forest because of the many trees (german proverb),

    cheers, Connie


    Hi Connie,

    The plugin doesn’t have any functionality to add geocoders in post editors.

    But if you’re using MapPress to generate maps from the address, it is already geocoding each address into a lat/lng. With some PHP code you could capture those values and save them to custom fields.

    I haven’t tested this code but it might help to get you started:

    function mysave($post_ID, $post) {
      // Get the first map & first poi for this post
      $maps = get_post_map_list($post->ID);
      // Get first map and its first poi
      if (!empty($maps) && !empty($map[0]->pois)) {
    	  $poi = $map[0]->pois[0];
          update_post_meta($post->ID, 'my_lat', $poi->point['lat']);
          update_post_meta($post->ID, 'my_lng', $poi->point['lng']);
    add_action('save_post', array(&$this, 'save_post'), 110, 2);

    Thank you, Chris,

    I will test this as soon as possible!

    Cheers, Connie

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.