A collection of maps API from Google maps and Mapbox (mostly experimental)
- Coordinate Geocoding
- Google Maps
- Map Box
- Region Boundary
- Open Street Overpass API
- osmnx lib
- Distance API
- Open Street Map (nx network graph)
- After Creating account and getting API Key Register it in the code
# Define your API key and endpoint
API_KEY = 'your_api_key_here'
- Add Address names to places you want to get geo coordinates
# provide address list
addresses = ['Ubungo Maji', 'Mbezi Louis']
- Code response list(longitude, latitude)
lat = result['results'][0]['geometry']['location']['lat']
lng = result['results'][0]['geometry']['location']['lng']
- After Creating Account and getting public key
// api_key looks like
* pk.eyJ1IjoiZWRkaWVndWxsZWQiLCJhIj......
- Add YOUR_MAPBOX_ACCESS_TOKEN
# add access token here
YOUR_MAPBOX_ACCESS_TOKEN = keys.API_key
- Add Address names to places you want to get geo coordinates
# provide list of addresses here
address_list = ['kigamboni']
- Output definition
response_body = {
"place_name": place_name,
"longitude" : coordinates[0],
"latitude" : coordinates[1],
"bbox_center" : center,
"boundary_square_matrix" : boundary
}
@@@ Check response.json to see complete mapbox response @@@
Just provide location address name and the method will find all coordinated for that region
Response From Overpass API is not very reliable and has complex queries as per requirements (Not satble)
from osmnx api call get_coordinates(str:)
address_name = "Kigamboni, Tanzania"
boundary_coords = get_coordinates(address_name)
boundary_coords : [(long), (lat)]
Getting distance from one point to another on a map. You can either get linear distance with Haversine Algorithm or get distance by following roads
# define starting and ending points
point1 = (39.275229073736654,-6.819505513688398)
point2 = (39.27989377640603,-6.821308691427461)
# call distance method
distance = get_distance(point1, point2) # for linear distance
road_distance = get_road_distance(point1, point2, "drive") # Following road distance