Get latitude and longitude of address

This script uses the `geocoder` library to find the latitude and longitude of a specified address using the OpenStreetMap provider. If successful, it returns a dictionary with map details including the latitude, longitude, zoom level, and marker information for the location. If the address cannot be located, it returns an error message.

Script windmill

by henri186 ยท 4/17/2024

  • Submitted by henri186 Python3
    Created 755 days ago
    1
    import geocoder
    2
    
    
    3
    def main(address: str) -> dict:
    4
        # Use geocoder to get the latitude and longitude of the given address
    5
        g = geocoder.osm(address)  # Using OpenStreetMap provider
    6
        if g.ok:
    7
            return { "map": { "lat": 40, "lon": 0, "zoom": 3, "markers": [{"lat": g.lat, "lon": g.lng, "title": "Home", "radius": 5, "color": "yellow", "strokeWidth": 3, "strokeColor": "Black"}]}}
    8
        else:
    9
            return {'error': 'Unable to find the location'}