These functions provide access geolocation features using the Google API.
Import
To use this library and its functions, you must use the import line at the beginning of your Base Python code.
import Geolocation
Get address from GeoPoint
Geolocation.get_address_from_geopoint(latitude,longitude, key)
Returns the address associated with the provided GeoPoint
Credit cost: 1
Parameters
- latitude:
str
latitude of the GeoPoint - longitude:
str
longitude of the GeoPoint - key:
str
Google API key
Return Value
list
list of dicts containing GeoPoint information
Example
-
Sample Code:
import Geolocation
value = Geolocation.get_address_from_geopoint("YOUR_LATITUDE","YOUR_LONGITUDE", "YOUR_API_KEY") - Return Value:
[{"geometry":
{"location_type":"ROOFTOP",
"viewport":
{"northeast":{"lat":33.8897619802915,"lng":-118.1983450197085},
"southwest":{"lat":33.8870640197085,"lng":-118.2010429802915}},
"location":{"lat":33.888413,"lng":-118.199694}},
"address_components":[
{"long_name":"4006","short_name":"4006","types":["street_number"]},
{"long_name":"East Alondra Boulevard","short_name":"E Alondra Blvd","types":["route"]},
{"long_name":"Compton","short_name":"Compton","types":["locality","political"]},
{"long_name":"Los Angeles County","short_name":"Los Angeles County","types":["administrative_area_level_2","political"]},
{"long_name":"California","short_name":"CA","types":["administrative_area_level_1","political"]},
{"long_name":"United States","short_name":"US","types":["country","political"]},
{"long_name":"90221","short_name":"90221","types":["postal_code"]},
{"long_name":"4669","short_name":"4669","types":["postal_code_suffix"]}],
"place_id":"ChIJlXGZHKTMwoAR7Tn_xz5MOd8",
"formatted_address":"4006 East Alondra Boulevard, Compton, CA 90221, USA",
"types":["street_address"]
},
...
]
Exceptions
- Exception
- GeoPoint invalid or not specified
Get GeoPoint from address
Geolocation.get_geopoint_from_address(address, key)
Returns the GeoPoint associated with the provided address
Credit cost: 1
Parameters
- address:
str
- key:
str
Google API key
Return Value
list
list of dicts containing GeoPoint information
Example
-
Sample Code:
import Geolocation
value = Geolocation.get_geopoint_from_address("YOUR_ADDRESS", "YOUR_API_KEY")
- Return Value:
[{"geometry":
{"location_type":"ROOFTOP",
"viewport":
{"northeast":{"lat":33.8897619802915,"lng":-118.1983450197085},
"southwest":{"lat":33.8870640197085,"lng":-118.2010429802915}},
"location":{"lat":33.888413,"lng":-118.199694}},
"address_components":
[{"long_name":"4006","short_name":"4006","types":["street_number"]},
{"long_name":"East Alondra Boulevard","short_name":"E Alondra Blvd","types":["route"]},
{"long_name":"Compton","short_name":"Compton","types":["locality","political"]},
{"long_name":"Los Angeles County","short_name":"Los Angeles County","types":["administrative_area_level_2","political"]},
{"long_name":"California","short_name":"CA","types":["administrative_area_level_1","political"]},
{"long_name":"United States","short_name":"US","types":["country","political"]},
{"long_name":"90221","short_name":"90221","types":["postal_code"]},
{"long_name":"4669","short_name":"4669","types":["postal_code_suffix"]}],
"place_id":"ChIJlXGZHKTMwoAR7Tn_xz5MOd8",
"formatted_address":"4006 East Alondra Boulevard, Compton, CA 90221, USA",
"types":["street_address"]
},
...
]
Exceptions
- Exception
- Address invalid or not specified
Get location from IP
Geolocation.get_location_from_ip(ip, user, key)
Returns the GeoPoint associated with provided IP, provided by MaxMind API.
See http://dev.maxmind.com/geoip/ for more information and to create an account.
Credit cost: 1
Parameters
- ip:
str
- user:
str
MaxMind user id - key:
str
MaxMind API key
Return Value
dict
dict containing location information
Example
-
Sample Code:
import M1Geolocation
value =M1Geolocation.get_location_from_ip("YOUR_IP")
- Return Value:
{
"city": {
"names": {}
},
"country": ...,
"continent": ...,
...
}
Exceptions
- Exception
- IP address is not valid, is not public, or was not specified