none
Reverse GeoCoding with WebClient : does it work ? RRS feed

  • Question

  • Hi,

    I have as input a simple Decimal Gps Lat/Lon point : let's say 40.766201, -73.977547.

    I make a simple request on a free reverse geocoding app like this :

    https://nominatim.openstreetmap.org/reverse?format=xml&lat=40.766201&lon=-73.977547&zoom=18&addressdetails=1
    Browser's response is a simple xml like this :

    <reversegeocode timestamp="Fri, 14 Feb 20 08:55:13 +0000" attribution="Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright" querystring="format=xml&lat=40.766201&lon=-73.977547&zoom=18&addressdetails=1">
    <result place_id="150418826" osm_type="way" osm_id="265147718" lat="40.765983399999996" lon="-73.97757174590839" boundingbox="40.7658422,40.7661164,-73.977763,-73.9774029">
    128, Central Park South, Columbus Circle, Manhattan Community Board 5, Manhattan, New York County, New York, 10019, Stati Uniti d'America
    </result>
    <addressparts>
    <house_number>128</house_number>
    <road>Central Park South</road>
    <suburb>Manhattan</suburb>
    <city>New York</city>
    <county>New York County</county>
    <state>New York</state>
    <postcode>10019</postcode>
    <country>Stati Uniti d'America</country>
    <country_code>us</country_code>
    </addressparts>
    </reversegeocode>

    Which is what I need, and in particular Country / City / Road / House_Number.

    Now, on the Application side, I use a WebClient Object to obtain the same string :

     Dim WC As New System.Net.WebClient
     WC.Encoding = System.Text.Encoding.UTF8
     Dim wcRequest As String = "https://nominatim.openstreetmap.org/reverse?format=xml&lat=40.766201&lon=-73.977547&zoom=18&addressdetails=1"
     Dim wcResult As String = WC.DownloadString(wcRequest)

    I always get Error WebException on WC.DownloadString() Method as "Remote Server Error (403) Not Allowed".

    Allowed using a browser and not allowed using code ? What's wrong ?

    Thanks to anyone able to help...


    Friday, February 14, 2020 9:09 AM

Answers

  • For example =>

    Dim WC As New System.Net.WebClient
    WC.Encoding = System.Text.Encoding.UTF8
    Dim wcRequest As String = "https://nominatim.openstreetmap.org/reverse?format=xml&lat=40.766201&lon=-73.977547&zoom=18&addressdetails=1"
    WC.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; WOW64; rv: 52.0) Gecko/20100101 Firefox/52.0 SeaMonkey/2.49.4")
    Dim wcResult As String = WC.DownloadString(wcRequest) 

    • Marked as answer by MarcoGG Friday, February 14, 2020 10:57 AM
    Friday, February 14, 2020 10:08 AM

All replies

  • UserAgent must be filled

    (tested on Windows 10)

    Friday, February 14, 2020 9:50 AM
  • UserAgent must be filled

    (tested on Windows 10)

    Thanks, but I don't know where to use it. Is it a parameter that has to be added to my https request string ? 

    Which string should be used ? If you could provide an example that would be nice.

    Friday, February 14, 2020 10:01 AM
  • For example =>

    Dim WC As New System.Net.WebClient
    WC.Encoding = System.Text.Encoding.UTF8
    Dim wcRequest As String = "https://nominatim.openstreetmap.org/reverse?format=xml&lat=40.766201&lon=-73.977547&zoom=18&addressdetails=1"
    WC.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; WOW64; rv: 52.0) Gecko/20100101 Firefox/52.0 SeaMonkey/2.49.4")
    Dim wcResult As String = WC.DownloadString(wcRequest) 

    • Marked as answer by MarcoGG Friday, February 14, 2020 10:57 AM
    Friday, February 14, 2020 10:08 AM
  • For example =>

    Dim WC As New System.Net.WebClient
    WC.Encoding = System.Text.Encoding.UTF8
    Dim wcRequest As String = "https://nominatim.openstreetmap.org/reverse?format=xml&lat=40.766201&lon=-73.977547&zoom=18&addressdetails=1"
    WC.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; WOW64; rv: 52.0) Gecko/20100101 Firefox/52.0 SeaMonkey/2.49.4")
    Dim wcResult As String = WC.DownloadString(wcRequest) 

    It seems it can work regardless of what I put in that "user_agent" parameter. That sounds strange, however it works. Thanks again.

    Friday, February 14, 2020 10:57 AM