<?php



/**

* Return longitude and latitude Coordinates from the given IP

*/



function IPtoCoords($ip)

{



	$dom = new DOMDocument();

	$ipcheck = ip2long($ip);

	

	if($ipcheck == -1 || $ipcheck === false)

    	@trigger_error('Invalid IP, what are you doing? :|', E_USER_ERROR);

	else

		$uri = 'http://freegeoip.appspot.com/xml/' . $ip;



	@$dom->load($uri);

	

	$CountryName	= $dom->getElementsByTagName('CountryName')->item(0)->nodeValue;

	$RegionName 	= $dom->getElementsByTagName('RegionName')->item(0)->nodeValue;

	$City 			= $dom->getElementsByTagName('City')->item(0)->nodeValue;	

	$Latitude 		= $dom->getElementsByTagName('Latitude')->item(0)->nodeValue;

	$Longitude 		= $dom->getElementsByTagName('Longitude')->item(0)->nodeValue;

	

	$location = "";

	

	if ($Latitude == "" || $Longitude == "")

	{

		return false;	

	}

	else

	{

		if ($City != "")

			$location = $City;

		else if ($RegionName != "")

			$location = RegionName;

		else if ($CountryName != "")

			$location = CountryName;

	}

	return array('location' => $location, 'longitude' => $Longitude, 'latitude' => $Latitude);

}



/*

function IPtoCoords($ip)

{

	@$dom = new DOMDocument();



	@$ipcheck = ip2long($ip);

    if($ipcheck == -1 || $ipcheck === false)

    	@trigger_error('Invalid IP, what are you doing? :|', E_USER_ERROR);

	else

		$uri = 'http://api.hostip.info/?ip=' . $ip;



	@$dom->load($uri);

	@$location = (strpos($dom->getElementsByTagName('name')->item(1)->nodeValue, 'Unknown') === false)

					? $dom->getElementsByTagName('name')->item(1)->nodeValue

					: $dom->getElementsByTagName('countryAbbrev')->item(0)->nodeValue;

	

	if($location == 'XX')

		return false;

	else

	{

		@$dom->load('http://local.yahooapis.com/MapsService/V1/geocode?appid='.Yahoo_Key.'&location='.$location);

		$longitude = @$dom->getElementsByTagName('Longitude')->item(0)->nodeValue;

		$latitude  = @$dom->getElementsByTagName('Latitude')->item(0)->nodeValue;

		return array('location' => $location, 'longitude' => $longitude, 'latitude' => $latitude);

	}

}

*/

?>