Generate Map from PHP

Home Forums MapPress Support Generate Map from PHP

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #15668
    hawkesley
    Participant

    I would like to generate a Map from pHP as described in the docs.
    My code however generates this.
    >> biggermap
    How to go about this?
    $mymap = new Mappress_Map(array(“width” => 600));

    $mypoi_1 = new Mappress_Poi(array(“title” => “Poscode KT17”, “body” => “Epsom, Surrey”, “point” => array(“lat” => 51.34, “lng” => -0.24)));
    $mypoi_2 = new Mappress_Poi(array(“title” => “Poscode KT18”, “body” => “Epsom, Surrey”, “point” => array(“lat” => 51.31, “lng” => -0.26)));
    $mymap->pois = array($mypoi_1,$mypoi_2);
    echo $mymap->display();`
    Thanks

    #15670
    Chris
    Keymaster

    Hi,

    Your code is fine – I just put it into my test site and it works to display the map. I think it may not be working for you because of a syntax error:

    – Check that you’re not using ‘smart quotes’. Some software like Microsoft Word will replace a basic quote (“) with a fancy quote, which doesn’t work in PHP

    Here’s a working copy from my test site – you could try copying and pasting this.

    
    <?php
    $mymap = new Mappress_Map(array("width" => 600));
    
    							$mypoi_1 = new Mappress_Poi(array("title" => "Poscode KT17", "body" => "Epsom, Surrey", "point" => array("lat" => 51.34, "lng" => -0.24)));
    							$mypoi_2 = new Mappress_Poi(array("title" => "Poscode KT18", "body" => "Epsom, Surrey", "point" => array("lat" => 51.31, "lng" => -0.26)));
    							$mymap->pois = array($mypoi_1,$mypoi_2);
    							echo $mymap->display();
    ?>
    
    #15672
    hawkesley
    Participant

    Hi Chris,
    Thanks for coming back. I get the same result ie bigger map.
    My code is in a custom wordpress and I have not copied any of the mappress templates into it. I am using NETbeans which has always been fine for ” $”
    I must have missed something?

    #15673
    hawkesley
    Participant

    Just thought I would check the arrays and this
    echo “

    ";
                                    print_r($mypoi_1);
                                    echo "

    “;
    echo “

    ";
                                    print_r($mypoi_2);
                                    echo "

    “;
    gives
    Mappress_Poi Object
    (
    [address] =>
    [body] => Epsom, Surrey
    [correctedAddress] =>
    [iconid] =>
    [point] => Array
    (
    [lat] => 51.34
    [lng] => -0.24
    )

    [poly] =>
    [kml] =>
    [title] => Poscode KT17
    [type] =>
    [viewport] =>
    [postid] =>
    [url] =>
    )
    Mappress_Poi Object
    (
    [address] =>
    [body] => Epsom, Surrey
    [correctedAddress] =>
    [iconid] =>
    [point] => Array
    (
    [lat] => 51.31
    [lng] => -0.26
    )

    [poly] =>
    [kml] =>
    [title] => Poscode KT18
    [type] =>
    [viewport] =>
    [postid] =>
    [url] =>
    )

    #15674
    Chris
    Keymaster

    Hi,

    Sorry, but I don’t know – I think it’s something unique to your site.

    If you’d like to provide a URL or email me the source, I can try to spot it for you.

    Otherwise, try starting from a simplified setup:
    – deactivate ALL other plugins
    – switch to a standard theme like 2014
    – make your modification

    Then reactivate to find where the problem lies.

    If you do the above and it doesn’t work, you can also leave everything deactivated and send me a login, and I’ll try to take a look for you.

    #15675
    hawkesley
    Participant

    Ok I will try that.
    I am using twenty ten.
    Site is just localhost at present.Wordpress of course.
    If it fails again I will email the source.

    As a seperate attack on this problem I have also tried to programmatically create a post with my custom field to generate a Map.
    The post is generated but not the map.
    I first create a draft post, update the custom field and then update the post status to publish.
    Any thoughts on this approach appreciated.
    //create a new post to create a new map.
    $postcode= ‘KT17’;
    global $user_ID;
    $my_post = array(
    ‘post_title’ => ‘Epsom’,
    ‘post_content’ => ‘Postcodes’,
    ‘post_status’ => ‘draft’,
    ‘post_date’ => date(‘Y-m-d H:i:s’),
    ‘post_author’ => $user_ID,
    ‘post_type’ => ‘post’,
    ‘post_category’ => array(0)
    );
    $new_post_id = wp_insert_post( $my_post );
    if ($new_post_id == 0) {
    echo ‘Could not create the post.’;
    }
    else {
    echo ‘New post created.’;
    }
    update_post_meta($new_post_id, ‘postcode’, $postcode);//add the custom field
    $status= ‘publish’;//set status to publish

    #15676
    Chris
    Keymaster

    Hi,

    MapPress can generate maps from custom fields, but it’s really intended for use from the WP post editor or during data imports, not from PHP programs.

    There are two problems with the code above:
    1. It looks like you’re setting a variable $status to ‘publish’, not actually publishing the post.

    2. When post data (or status) is updated, try calling wp_update_post() to trigger the ‘save_post’ action. MapPress uses that hook.

    You might also want to try get this working from the admin first, before trying to call it from a program:
    1. Edit the post in the WP post editor
    2. Set your custom fields
    3. Publish to create the map.

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