map search with google maps API

hi,

i'm quite happy about the map search I integrated for member search & event search so i wanted to share it with you guys.

the fonction uses google maps API to position on a map members (or events).

the following code can be copy/paste in a new php file and used to create a new item in the menu through admin pannel builder/Navigation Menu Build for member search (it's almost the same thing with event, the 'Profiles' table changes to 'SDatingEvents'):

<?

/***************************************************************************
*                            Dolphin Smart Community Builder
*                              -----------------
*     begin                : Mon Mar 23 2006
*     copyright            : (C) 2006 BoonEx Group
*     website              : http://www.boonex.com/
* This file is part of Dolphin - Smart Community Builder
*
* Dolphin is free software. This work is licensed under a Creative Commons Attribution 3.0 License.
* http://creativecommons.org/licenses/by/3.0/
*
* Dolphin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the Creative Commons Attribution 3.0 License for more details.
* You should have received a copy of the Creative Commons Attribution 3.0 License along with Dolphin,
* see license.txt file; if not, write to marketing@boonex.com
***************************************************************************/


require_once( 'inc/header.inc.php' );
require_once( BX_DIRECTORY_PATH_INC . 'design.inc.php' );
require_once( BX_DIRECTORY_PATH_INC . 'profiles.inc.php' );

$_page['name_index'] = 100;
$_page['header'] = _t("_Google Maps", $site['title']);
$_page['header_text'] = _t("_Google Maps");
$_page['css_name'] = 'browse.css';

check_logged();

$_ni = $_page['name_index'];
$_page_cont[$_ni]['page_main_code']   = PageGoogleMaps();

PageCode();

function PageGoogleMaps()
{

$MySQL = new CMySQL;
$marker = '';
$res = db_res( "SELECT * FROM `Profiles`" );

while($row=mysql_fetch_array($res,MYSQL_ASSOC))
{
$adresse = '';
$adresse=$row["Address"].", ".$row["City"].", ".$row["Country"];
$marker=$marker."showAddress(\" ".$adresse." \", \"http:\/\/yoursite\//".$row[NickName]." \");";
//echo $row[NickName].$adresse."<br>";
}

//echo $marker;

$ret = "
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:v=\"urn:schemas-microsoft-com:vml\">
<head>
<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\"/>
<title>Google Maps API Example: Simple Geocoding</title>
<script src=\"http://maps.google.com/maps?file=api&v=2.x&key=yourgooglemapsAPIkey\" type=\"text/javascript\"></script>
<script type=\"text/javascript\">

var map = null;
var geocoder = null;
var adress = null;

// Create a base icon for all of our markers that specifies the
// shadow, icon dimensions, etc.
var baseIcon = new GIcon();
baseIcon.shadow = \"http://www.google.com/mapfiles/shadow50.png\";
baseIcon.iconSize = new GSize(20, 34);
baseIcon.shadowSize = new GSize(37, 34);
baseIcon.iconAnchor = new GPoint(9, 34);
baseIcon.infoWindowAnchor = new GPoint(9, 2);
baseIcon.infoShadowAnchor = new GPoint(18, 25);

function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById(\"map_canvas\"));
address = \"Bourges, FR\";
//map.setCenter(new GLatLng(37.4419, -122.1419), 13);       
geocoder = new GClientGeocoder();

// Retrieve location information, pass it to addToMap()
geocoder.getLatLng(address, function(point)
{
// Center the map on this point
map.setCenter(point, 5);
}
);

map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());

".$marker."
}
}

function createMarker(point, index, url) {
// Create a lettered icon for this point using our icon class
var letter = String.fromCharCode(\"A\".charCodeAt(0) + index);
var letteredIcon = new GIcon(baseIcon);
//letteredIcon.image = \"http://www.google.com/mapfiles/marker.png\";
letteredIcon.image = \"http://yoursite/media/images/youricon.png\";

// Set up our GMarkerOptions object
markerOptions = { icon:letteredIcon };
var marker = new GMarker(point, markerOptions);

GEvent.addListener(marker, \"click\", function() {
marker.openInfoWindowHtml(\"<a href=\" + url + \">click for more information<\/a> on the Member\" + \"</b>\");
});
return marker;
}

function showAddress(address, url) {
if (geocoder) {
geocoder.getLatLng(address,function(point) {
if (point) {map.addOverlay(createMarker(point, 0, url));}
});
}

}

</script>
</head>

<body onload=\"initialize()\" onunload=\"GUnload()\">
<div id=\"map_canvas\" style=\"width: 900px; height: 600px\"></div>
</body>
</html>

";
return $ret;
}

?>

if you have any question, do not hesitate.

you can check what it looks like at:

http://www.facecook.org/buddymapsearch.php for member

or:

http://www.facecook.org/mapsearch.php for event

however if the location search engine now works for me, I still have some issue to make work the search based on date critera (see another post for me). have anyone experienced such issue?

thanks

yanno

Quote · 29 Mar 2009

Hi Yanno,

Thanks for sharing! :) I just tried your code to draw a map of events but I'm just getting a blank page :(

Any clue?

Thank

Quote · 8 Apr 2009

hi,

have you copy/paste the code using your own API key?

I had this a couple of time. once it was due to wrong paramter I was passing throught he show.addres function and the other was most likeyl due to a temporary failure from the host since it worked the day after.

can you copy/paste you code?

cheers

yann

Quote · 9 Apr 2009

Hi Yann,

Yes, I did change the key with my own and replaced 'Profiles' with 'SDatingEvents' as per your instructions; no other changes though. Is it exactly the same code for 'events'?

Thanks again :)

Quote · 11 Apr 2009

hi,

i haven't notice i get a blank page with internet explorer! have you tried with firefox?

i will double check what's wrong with internet explorer.

it's supposed to be the same code.

regards

yann

Quote · 16 Apr 2009

Hello Yann,

Yes I'm having that exact same problem with IE 8, but it works great with Firefox and Safari. Did you find a solution for IE?

Thank you!

Quote · 11 May 2009

nop sorry. you actually made me realise the issue was with IE!!

any idea ?

i'm stuck

Quote · 19 May 2009
 
 
Below is the legacy version of the Boonex site, maintained for Dolphin.Pro 7.x support.
The new Dolphin solution is powered by UNA Community Management System.