WordPress.org

Support

Support » Plugins and Hacks » MapPress Easy Google Maps » [Plugin: MapPress Easy Google Maps] Mappress API

[Plugin: MapPress Easy Google Maps] Mappress API

  • Hi Chris and thanks for this excellent plugin of yours

    it works very very well when I’m using the shortcodes, anyhow I’d would like to use the API for some posts, unfortunately can’t get it to display maps

    here is the code I’ve set


    $mymap = new Mappress_Map( array( 'width' => 600, 'height' => 450 ) );
    // si get_post_meta avec type = true, on recupere une chaine, sinon un array
    $address = get_post_meta($post->ID, 'adresse',false)
    $mypoi = new Mappress_Poi( array( 'address' => $address[0], 'title' => get_the_title($post->ID), 'body' => $address[0] ) );
    $mymap->pois = array($mypoi);
    $mymap->display();

    and there is the firebug console error


    a is null
    [Break on this error] za(Xd[A],function(){if(this.b){switch(...[A].Wa=function(a,b){this.d.Wa(a,b)};
    main.js line 26

    Seems like google API is waiting for some unset data ?

    I’ve tried to set a few more parameters as well and still get the same error

    Any hint ?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author chrisvrichardson

    @chrisvrichardson

    Hi,

    I think that error may be because your address must be geocoded. You need to geocode the markers before you call display().

    Take a look at the geocode() function and also the save_post() function to see how to handle the goecoding results, along with google’s documentation:
    http://code.google.com/apis/maps/documentation/geocoding/

    If you just want to display a map from addresses in a custom field – if you’re patient, I’m currently working on adding this into the plugin itself, but it may be a while before I get it done.

    How do I dynamically get the map’s ID?

    I also would love the ability to generate a map using the custom fields. I already have custom fields for address, city, state, zip.
    I tried to pass this to Mappress via:

    $street = get_post_meta($post->ID, 'address', true);
                    $city = get_post_meta($post->ID, 'city', true);
                    $state = get_post_meta($post->ID, 'state', true);
                    $zip = get_post_meta($post->ID, 'zip', true);
                    $address = $street.' '.$city.' '.$zip;

    ..then…

    $mymap = new Mappress_Map(array("width" => 425));
                                    $mypoi = new Mappress_Poi( array( 'address' => $address, 'title' => get_the_title($post->ID), 'body' => $address ) );
                                    $mypoi->geocode();
                                    $mymap->pois = array($mypoi);
                                    $mymap->display();

    Borrowed some of your code as well OP. 🙂
    But it does not work.
    BTW This plug-in kicks ass!

    Ok.. I installed another plug-in that geocodes based on custom fields(address,stree,city,zip) and creates two new custom fields(lat,lgn). I tried using the code suggested on the MapPress page with both the data from these fields and manually substituting the actual lat and lgn. MapPress wouldnot display the map.
    So…

    $mymap = new Mappress_Map(array("width" => 425, "height" => 350));
    $mypoi = new Mappress_Poi(array( "point" => array("lat" => 34.0213670, "lng" => -81.3380449)));
    $mymap->pois = array($mypoi);
    $mymap->display();

    ..does not work.
    What are we doing wrong here?

    well

    I have had a look at the geocode function and this is what I get when sending the datas directly to google through

    http://maps.google.com/maps/api/geocode/json?address=8bis avenue du palais des expositions, 66000 perpignan&sensor=false&output=json&region=FR&language=FR

    returns

    {
    “status”: “OK”,
    “results”: [ {
    “types”: [ “street_address” ],
    “formatted_address”: “8 Avenue du Palais des Expositions, 66000 Perpignan, France”,
    “address_components”: [ {
    “long_name”: “8”,
    “short_name”: “8”,
    “types”: [ “street_number” ]
    }, {
    “long_name”: “Avenue du Palais des Expositions”,
    “short_name”: “Avenue du Palais des Expositions”,
    “types”: [ “route” ]
    }, {
    “long_name”: “Perpignan”,
    “short_name”: “Perpignan”,
    “types”: [ “locality”, “political” ]
    }, {
    “long_name”: “Pyrénées-Orientales”,
    “short_name”: “66”,
    “types”: [ “administrative_area_level_2”, “political” ]
    }, {
    “long_name”: “Languedoc-Roussillon”,
    “short_name”: “Languedoc-Roussillon”,
    “types”: [ “administrative_area_level_1”, “political” ]
    }, {
    “long_name”: “France”,
    “short_name”: “FR”,
    “types”: [ “country”, “political” ]
    }, {
    “long_name”: “66000”,
    “short_name”: “66000”,
    “types”: [ “postal_code” ]
    } ],
    “geometry”: {
    “location”: {
    “lat”: 42.7047338,
    “lng”: 2.8932853
    },
    “location_type”: “RANGE_INTERPOLATED”,
    “viewport”: {
    “southwest”: {
    “lat”: 42.7015923,
    “lng”: 2.8901326
    },
    “northeast”: {
    “lat”: 42.7078876,
    “lng”: 2.8964279
    }
    },
    “bounds”: {
    “southwest”: {
    “lat”: 42.7047338,
    “lng”: 2.8932752
    },
    “northeast”: {
    “lat”: 42.7047461,
    “lng”: 2.8932853
    }
    }
    },
    “partial_match”: true
    } ]
    }

    which seems absolutely perfect.

    So it should work with this php code:

    $mymap = new Mappress_Map( array( “width” => 600, “height” => 450 ) );
    var_dump($address);
    $mypoi = new Mappress_Poi( array( “title” => “”, “body” => “”, “point” => array(“address” => $address[0]) ) );
    $mypoi->geocode( );
    $mymap->pois = array($mypoi);
    $mymap->display( );

    the var dump returns:

    array(1) { [0]=> string(63) “8bis, avenue du palais des expositions, 66000 Perpignan, France” }

    but my POI doesn’t show up 🙁

    Any other hint ?

    Sincerely
    Olivier

    Sorry, the proper php code should be:

    $mymap = new Mappress_Map( array( “width” => 600, “height” => 450 ) );
    $mypoi = new Mappress_Poi( array( ‘address’ => $address[0], ‘title’ => “”, ‘body’ => $address[0] ) );
    $mypoi->geocode( );
    $mymap->pois = array($mypoi);
    var_dump($mymap->pois);
    $mymap->display( );

    The pois var dump returns:

    array(1) { [0]=> object(Mappress_Poi)#187 (8) { [“point”]=> array(2) { [“lat”]=> float(42.7047338) [“lng”]=> float(2.8932853) } [“title”]=> string(34) “8 Avenue du Palais des Expositions” [“titleUrl”]=> NULL [“body”]=> string(23) “66000 Perpignan, France” [“address”]=> string(63) “8bis, avenue du palais des expositions, 66000 Perpignan, France” [“correctedAddress”]=> string(59) “8 Avenue du Palais des Expositions, 66000 Perpignan, France” [“iconid”]=> NULL [“viewport”]=> array(2) { [“sw”]=> array(2) { [“lat”]=> float(42.7015923) [“lng”]=> float(2.8901326) } [“ne”]=> array(2) { [“lat”]=> float(42.7078876) [“lng”]=> float(2.8964279) } } } }

    which is lot better as the lat and lng datas are there…

    but still no map

    Hi upyup,

    It took me a while realize that you forgot to put the echo before $mymap->display( ); and you can remove the var_dump($mymap->pois);

    It should look like the following :

    $mymap = new Mappress_Map( array( "width" => 600, "height" => 450 ) );
    $mypoi = new Mappress_Poi( array( 'address' => $address[0], 'title' => "", 'body' => $address[0] ) );
    $mypoi->geocode( );
    $mymap->pois = array($mypoi);
    echo $mymap->display( );
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘[Plugin: MapPress Easy Google Maps] Mappress API’ is closed to new replies.
Skip to toolbar