Simon McManus

Javascript Engineer

Mashing Up BT Web21c Location service with Google Maps

This example combines the  two post  (Google Maps API and your location from the sdk)to automatically look up a phones location and then map it straight to a google map box.

The code is below, please note you should only need to change the four variables at the top of the code :
<?php 

require\_once(dirname(\_\_FILE\_\_) . '/../../web21c.php'); 

require\_once(dirname(\_\_FILE\_\_) . '/../common.php');
//&nbsp; command to locate a mobile deviice 

//&nbsp; - set these to sensible values
$deviceId = 'tel:+PHONENUMBER'; 

$username = [USERNAME@MAIL.COM](mailto:USERNAME@MAIL.COM); 

$password = "YOUR PASSWORD"; 

$googleAPIKey = "YOUR GOOGLE API KEY";
$web21c = new Web21c($applicationName, $environment);
// login as a user 

$wla = $web21c->WhiteLabelAuthentication(); 

$wla->login($username, $password);
&nbsp;//&nbsp; locate mobile 

$location = $web21c->Location(); 

$location->web21cUser = $wla->web21cUser;
try 

{ 

&nbsp;$r = $location->getGeoLocation($deviceId); 

} 

catch (Web21cPermissionDeniedException $e) 

{ 

&nbsp;print "requesting device owner's permission to be located ..n"; 

&nbsp;print "try again later when the owner may have respondedn"; 

&nbsp;$access = $web21c->LocationPermission(); 

&nbsp;$access->web21cUser = $wla->web21cUser; 

&nbsp;$access->requestPermission($deviceId); 

}
// var\_dump($r->geoLocation);
echo 'Longitude : '.$r->geoLocation->longitude. '<br />'; 

echo 'Latitude : '.$r->geoLocation->latitude. '<br />'; 

echo "Click below to see the location of mobile number ".$deviceId."<br />"; 

echo "<a href='http://maps.google.com?q=".$r->geoLocation->latitude.",%20".$r->geoLocation->longitude."'>Google Maps</a> "; 

//echo 'start : '.$r->getGeoLocation()->getLongitude(); 

?> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 

&nbsp; "[http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd](http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd)"> 

<html xmlns="[http://www.w3.org/1999/xhtml](http://www.w3.org/1999/xhtml)"> 

&nbsp; <head> 

&nbsp;&nbsp;&nbsp; <script src="[http://maps.google.com/maps?file=api&v=2&key=<?=$googleAPIKey](http://maps.google.com/maps?file=api&v=2&key=<?=$googleAPIKey)?>" 

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; type="text/javascript"></script>
</head> 

&nbsp; <body onload="load()" onunload="GUnload()"> 

&nbsp;&nbsp;&nbsp; <p> 

&nbsp;&nbsp;<script type="text/javascript">&nbsp;&nbsp;&nbsp; 

&nbsp;&nbsp;function load() 

&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 

&nbsp;&nbsp;&nbsp;if (GBrowserIsCompatible()) 

&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 

&nbsp;&nbsp;&nbsp;&nbsp;var map = new GMap2(document.getElementById("map"));&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 

&nbsp;&nbsp;&nbsp;&nbsp;var map = new GMap2(document.getElementById("map")); 

&nbsp;&nbsp;&nbsp;&nbsp;map.setCenter(new GLatLng(<?=$r->geoLocation->latitude?>, <?=$r->geoLocation->longitude?>), 13); 

&nbsp;&nbsp;&nbsp;&nbsp;map.openInfoWindow(map.getCenter(), 

&nbsp;&nbsp;&nbsp;&nbsp;document.createTextNode("Simon is here ")); 

&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp; 

&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp; 

&nbsp;&nbsp; 

&nbsp;&nbsp;</script> 

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="style1">BT SDK Location Service </span></p> 

&nbsp;&nbsp;&nbsp; <div id="map" style="width: 500px; height: 300px"></div> 

&nbsp; </body> 

</html> 

&nbsp;
July 20th 2007