Get Distance Between Two Postal Codes

Nisala88

Well-known member
  • Oct 24, 2006
    4,206
    735
    113
    ~Madhouse~
    කවුරුහරි දන්නවද API එකක්, postal codes දෙකක් දුන්නම ඒ දෙක අතර driving distance එක ගන්න පුළුවන්?
    ලංකාවට හොදට වැඩ කරන එකක්, ගොඩක් ඒවා ලංකාවට වැඩ කරන්නේ නෑ
     
    • Like
    Reactions: EnIgma001

    Nisala88

    Well-known member
  • Oct 24, 2006
    4,206
    735
    113
    ~Madhouse~
    Lankawe postalcodes walata wenama landmark deela na neda bn?.
    Ex - 10200 - whole athurugiriya city.
    Ethakota uba distance eka ganne center idalada?
    ehema exact location eka ganna widihak ne ban. eka nisa mulu city ekama ganna baluwe.
    Exact address dekak athara driving distance eka ganna puluwan widihak thiyenawada
     

    Nisala88

    Well-known member
  • Oct 24, 2006
    4,206
    735
    113
    ~Madhouse~
    Google GeoCode API check karala balanna

    Postal Address ganna puluwan, eke thiyanawa lat & lng
    ewagen aye distance eka ganna : driving mode distance

    meka check kare ne me wadeta. Meka machan maseta limited neda?

    ඒ පාර උබ මොකෝ කොරන්න යන්නේ, ගූගල් මැප් එකටත් කෙලවෙන එකක් නෑනේ :P

    ne ban. me project ekakata :D
    ------ Post added on Sep 26, 2022 at 4:03 PM
     
    • Love
    Reactions: nvhcc89

    NecroMonger

    Active member
  • Dec 27, 2011
    145
    63
    28
    Can't tell you a good solution because you are not sharing the whole problem. However, here is an approach that might work.

    1. Identify Polygons for the postal code (This is needs to be a vector of coordinates denoting a polygon)
    2. Calculate the center of two polygons you want to measure the distance between
    3. For the two locations, find out the nearest points in a road using a service like the Google Roads Api
    4. Now measure the distance between the two road locations.
    Like I said, this is based on what you shared, maybe we can make it better if you share your real problem. Sinhalen type karanna wela yana nisa mehema gahuwe.
     

    Nisala88

    Well-known member
  • Oct 24, 2006
    4,206
    735
    113
    ~Madhouse~
    Can't tell you a good solution because you are not sharing the whole problem. However, here is an approach that might work.

    1. Identify Polygons for the postal code (This is needs to be a vector of coordinates denoting a polygon)
    2. Calculate the center of two polygons you want to measure the distance between
    3. For the two locations, find out the nearest points in a road using a service like the Google Roads Api
    4. Now measure the distance between the two road locations.
    Like I said, this is based on what you shared, maybe we can make it better if you share your real problem. Sinhalen type karanna wela yana nisa mehema gahuwe.

    The requirement is to get the driving distance between two addresses (source and destination) for a delivery. Thing is most of the APIs return the distance between two points, not the driving distance by road.
     

    NecroMonger

    Active member
  • Dec 27, 2011
    145
    63
    28
    The requirement is to get the driving distance between two addresses (source and destination) for a delivery. Thing is most of the APIs return the distance between two points, not the driving distance by road.

    That's doable right ?
    1. get the nearest roads using the Google Roads API (https://developers.google.com/maps/documentation/roads/nearest)
    2. Get the directions from the Directions API (https://developers.google.com/maps/documentation/directions/overview)
    Doesn't this solve your problem?

    The requirement is to get the driving distance between two addresses (source and destination) for a delivery. Thing is most of the APIs return the distance between two points, not the driving distance by road.
    Mapbox also has some APIs that might be able to help you

    https://docs.mapbox.com/help/glossary/directions-api/

    ------ Post added on Sep 26, 2022 at 10:52 PM
     

    pathumputha

    Well-known member
  • Feb 20, 2018
    3,284
    6,544
    113
    import googlemaps
    gmaps = googlemaps.Client(key='XXXXX')
    city1 = input("City 1 : ")
    city2 = input("City 2 : ")
    dist = gmaps.distance_matrix(city1,city2)['rows'][0]['elements'][0]
    print(dist)

    පොස්ටල් කෝඩ් එක නම් දන්නේ නෑ සිටීස් 2 දීල ඩිස්ටන්ස් එක ගන්න පුළුවන් (python)
     
    Last edited:
    • Love
    Reactions: Nisala88

    imhotep

    Well-known member
  • Mar 29, 2017
    14,824
    8
    35,333
    113
    කවුරුහරි දන්නවද API එකක්, postal codes දෙකක් දුන්නම ඒ දෙක අතර driving distance එක ගන්න පුළුවන්?
    ලංකාවට හොදට වැඩ කරන එකක්, ගොඩක් ඒවා ලංකාවට වැඩ කරන්නේ නෑ

    Try this out. The pgeocode Python library.

    pgeocode is a Python library for high performance off-line querying of GPS coordinates, region name and municipality name from postal codes. Distances between postal codes as well as general distance queries are also supported. The used GeoNames database includes postal codes for 83 countries.
    As per the documentation Srilanka (LK) is included.

    Currently, only queries within the same country are supported.

    For additional documentation see pgeocode.readthedocs.io.

    The SriLankan postal codes data available from https://github.com/symerio/postal-codes-data/blob/master/data/geonames/LK.txt
     
    Last edited:
    • Love
    Reactions: Nisala88

    kasun090354t

    Well-known member
  • Aug 21, 2011
    24,054
    36,054
    113
    කෑගල්ල
    Google GeoCode API check karala balanna

    Postal Address ganna puluwan, eke thiyanawa lat & lng
    ewagen aye distance eka ganna : driving mode distance
    අඩෝ ලංකාවේ තියනවාද මචං. Usa, canada වළනම් හොයාගෙන වෙනම තියන ඉන්නේ. පොඩි පොඩි app හදාදී සෑහෙන්න ඕනේ වෙනවා.
     

    Nisala88

    Well-known member
  • Oct 24, 2006
    4,206
    735
    113
    ~Madhouse~
    That's doable right ?
    1. get the nearest roads using the Google Roads API (https://developers.google.com/maps/documentation/roads/nearest)
    2. Get the directions from the Directions API (https://developers.google.com/maps/documentation/directions/overview)
    Doesn't this solve your problem?


    Mapbox also has some APIs that might be able to help you

    https://docs.mapbox.com/help/glossary/directions-api/

    ------ Post added on Sep 26, 2022 at 10:52 PM

    Thanks, machan :D I'll try these.