WP Greet Box icon
If you find BP-Tricks helpful, you should see our Premium BuddyPress Themes. Creating beautiful, responsive and flexible themes focused on BuddyPress is what we do well. Don't believe us? Why don't you check them out?

Show a Geo Map Widget like on BP.org

Place the following code anywhere you like. This can be in your (child theme’s) Sidebar.php file or in the Member-Header.php file (found in Members/Single/ in the theme directory)

<?php if ( $location = bp_get_profile_field_data( 'field=Location&user_id=' . bp_displayed_user_id() ) ) : ?>
 <div>
 <h3>Location <?php if ( bp_is_my_profile() ) : ?>· <a href="<?php echo bp_loggedin_user_domain() .'profile/edit/' ?>">Edit</a><?php endif; ?></h3>
 <script src="http://maps.google.com/maps?file=api&v=2.x&key=[YOUR API KEY]" type="text/javascript"></script>
 <script type="text/javascript">
 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 echo $location ?>'); } );
 </script>
 <div id="map_canvas" style="width: 100%; height: 150px; border: 1px solid #eee; overflow: hidden"></div>
 </div>
 <?php endif; ?>

You now have the same widget as on the profile pages on BP.org!

http://buddypress.org/community/groups/how-to-and-troubleshooting/forum/topic/profile-stats-and-location-in-profile-page-like-buddypress-org/
BuddyPress Hosting Guide Looking for quality BuddyPress hosting? We will guide you through all the available hosting options and help you find the best webhost for your next BuddyPress project!

Something about bowe

BuddyPress fanatic, WordPress Theme designer and MultiSite community builder. Proud co-founder of PressCrew. Loves to use awesome in every sentence. Often described as a Dutch Treehugging Hippie.

One Response to Show a Geo Map Widget like on BP.org

  1. hnla June 7, 2011 at 2:32 pm #

    I created a plugin a little while back to handle this basic map profile display, updating the google api to V3 and creating an admin page to allow for map config options and rendering of the map via action hooks on profile pages along with a basic widget for sidebar use (although sidebar placement isn’t hugely useful )
    http://buddypress.org/community/groups/bp-user-profile-map/