Skip to:
Content
Pages
Categories
Search
Top
Bottom

What does BP.org use to power the “current location” field in our profiles?


  • gregfielding
    Participant

    @gregfielding

    Is it simply an extended profile field, or is there some sort of geo-tagging code behind it?

Viewing 4 replies - 1 through 4 (of 4 total)

  • Boone Gorges
    Keymaster

    @boonebgorges

    It uses the Google Maps API and a piece of xprofile data (“Current Location”). Here’s a pared down version of what’s used on the site:

    `function bporg_insert_profile_info_column() {
    global $bp; ?>

    displayed_user->id ) ) : ?>

    Location ยท <a href="”>Edit

    var map = null;
    var geocoder = null;

    function initialize() {
    if (GBrowserIsCompatible()) {
    map = new GMap2(document.getElementById(“map_canvas”));
    map.setCenter(new GLatLng(0, 0), 35);
    geocoder = new GClientGeocoder();
    }
    }

    function showAddress(address) {
    if (geocoder) {
    geocoder.getLatLng(
    address,
    function(point) {
    if (point) {
    map.setCenter(point, 11);
    var marker = new GMarker(point);
    map.addOverlay(marker);
    map.addControl(new GSmallMapControl());
    }
    }
    );
    }
    }
    jQuery(document).ready( function() { initialize(); showAddress(”); } );

    <?php }
    add_action( ‘bp_before_member_activity_post_form’, ‘bporg_insert_profile_info_column’, 9 );
    add_action( ‘bp_before_member_groups_content’, ‘bporg_insert_profile_info_column’, 9 );
    add_action( ‘bp_before_followers_loop’, ‘bporg_insert_profile_info_column’, 9 );
    add_action( ‘bp_before_following_loop’, ‘bporg_insert_profile_info_column’, 9 );
    add_action( ‘bp_before_profile_content’, ‘bporg_insert_profile_info_column’, 9 );
    add_action( ‘bp_before_member_messages’, ‘bporg_insert_profile_info_column’, 9 );`

    [EDIT: Removed the API key and replaced with ‘KEYKEYKEY’. You’ll have to get your own from Google]


    gregfielding
    Participant

    @gregfielding

    Thanks Boone!

    That works like a charm with a new API key.

    Any thoughts on how to incorporate this geotagging into the activity filters? I need to find a way to filter activity by proximity.

    For example, all activity by members within 50 miles of you.


    Boone Gorges
    Keymaster

    @boonebgorges

    Thanks for the note about the API key. I removed it from the original post.

    The kind of sorting you’re talking about is possible but is quite a bit trickier. I have successfully used https://wordpress.org/extend/plugins/buddypress-geo/ is a starting point for that kind of filtering, but the repo version of the plugin is broken, and I’ve modified it fairly heavily to make it work for my projects. One day I hope to release a cleaned-up and improved version of BP Geo.

    The basic gist is that you need to (a) use Google’s geocoding to turn location info into lat/long which you then store, and (b) use some fancy math (nicely defined in bp-geo) to do the proximity filtering.


    gregfielding
    Participant

    @gregfielding

    Yeah…I was looking at that plugin and a couple of others out there that just don’t seem baked enough.

    My plan is to have visitors to my site enter a location and see activity from all members and groups near it as a default stream. I don’t need a bunch of fancy extras, just a proximity filter for members’ activities.

    I’d be happy to contribute or help somehow if you could get a new BP GEO to do this.

    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘What does BP.org use to power the “current location” field in our profiles?’ is closed to new replies.
Skip to toolbar