M1Geolocation Library

These functions provide access geolocation features using the Google API

Note: If you have a Google API key, it is recommended that you use the Geolocation Library to save credits.

Import

To use this library and its functions, you must use the import line at the beginning of your Base Python code.

import M1Geolocation

 

Get address from GeoPoint

M1Geolocation.get_address_from_geopoint(latitude,longitude)

Returns the address associated with the provided GeoPoint

Credit cost: 100

Parameters

  • latitudestr latitude of the GeoPoint
  • longitudestr longitude of the GeoPoint

Return Value

list list of dicts containing GeoPoint information

Example

  • Sample Code:

    import M1Geolocation
    value = M1Geolocation.get_address_from_geopoint("YOUR_LATITUDE","YOUR_LONGITUDE")
  • 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

M1Geolocation.get_geopoint_from_address(address)

Returns the GeoPoint associated with the provided address

Credit cost: 100

Parameters

  • addressstr

Return Value

list list of dicts containing GeoPoint information

Example

  • Sample Code:
import M1Geolocation
value = M1Geolocation.get_geopoint_from_address("YOUR_ADDRESS")
  • 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

M1Geolocation.get_location_from_ip(ip)

Returns the GeoPoint associated with provided IP, provided by MaxMind API.

Note: if you have a MaxMind account, it is recommended that you use the Geolocation Library to save credits.

Credit cost: 100

Parameters

  • ipstr

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