Including the API with javascript
You have to include the following script:
<script type="text/javascript" src="http://ip-geo.appspot.com/geo_data.js"><script>
It identify the geo location of the calling visitor by calling up to five
webservices. The result is the global geo object, the location results are in
the geo.ll-Array and some helper functions gives you access to the nearest
position or the next city.
After loading the dynamic part the static function part will loaded instantly
from http://ip-geo.appspot.com/geo_func.js (if not available).
If you included it before the geo_data.js not extra loading is initiated.
function getPosition
"geo.getPosition()" returns an object with the calculated, centered
position based on the different positions from the external IP-GEO provider.
var pos = geo.getPosition();
alert("your pos is"+pos.lat+","+pos.long);
function getLocation
Get the best city from the visitor. The method
"geo.getLocation()"
will find the best city based on the centered position.
var loc = geo.getLocation();
alert("Welcome from "+loc.city+" ("+loc.country+")");
function cityFound
To check if the visitor is located in a specific city, use the function
"geo.cityFound(cityList)":
if (geo.cityFound(['Burnaby', 'Vancouver'])) {
alert("Welcome from canada!");
}
function countryFound
To check if the visitor is located in a specific country, use the function
"geo.countryFound(countryList)":
var germans = ['Germany', 'Austria', 'Switzerland'];
if (geo.countryFound(germans)) { alert("Guten Tag!"); }
function distanceFromUser
Calculate the distance from the visitor to a given position.
var dis = geo.distanceFromUser(40.69, -74,05);
alert("The Statue of Liberty is "+dis+"km distance.");
The position map
For direct usage of the position map (seen on the
start page) include the
following javascript line into your html code.
document.write(geo.generate_map(500, 400));
The function "generate_map" produce the code for the static google map v2
and show all positions on the map.