Hi ahmadsubuhanl,
I have created the sample using the following documentation.
https://nominatim.org/release-docs/develop/api/Search/#examples
HTML
<asp:TextBox ID="txtLocation" runat="server"></asp:TextBox>
<asp:Button ID="btnFind" runat="server" Text="Find Location" OnClick="OnSubmit" />
<hr />
Latitude:
<asp:Label ID="lblLatitude" runat="server"></asp:Label><br />
Longitude:
<asp:Label ID="lblLongitude" runat="server"></asp:Label>
Namespaces
C#
using System.Net;
using System.Web;
using Newtonsoft.Json;
VB.Net
Imports System.Net
Imports System.Web
Imports Newtonsoft.Json
Code
C#
protected void OnSubmit(object sender, EventArgs e)
{
string url = string.Format("https://nominatim.openstreetmap.org/search?q={0}&format=json&addressdetails=1&limit=1", HttpUtility.UrlEncode(txtLocation.Text));
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
WebClient webClient = new WebClient();
webClient.Headers.Add(HttpRequestHeader.UserAgent, "/");
string json = webClient.DownloadString(url);
List<Place> places = JsonConvert.DeserializeObject<List<Place>>(json);
lblLatitude.Text = places[0].lat;
lblLongitude.Text = places[0].lon;
}
public class Address
{
public string historic { get; set; }
public string house_number { get; set; }
public string road { get; set; }
public string neighbourhood { get; set; }
public string suburb { get; set; }
public string borough { get; set; }
public string city { get; set; }
[JsonProperty("ISO3166-2-lvl4")]
public string ISO31662lvl4 { get; set; }
public string postcode { get; set; }
public string country { get; set; }
public string country_code { get; set; }
}
public class Place
{
public int place_id { get; set; }
public string licence { get; set; }
public string osm_type { get; set; }
public int osm_id { get; set; }
public string lat { get; set; }
public string lon { get; set; }
public string @class { get; set; }
public string type { get; set; }
public int place_rank { get; set; }
public double importance { get; set; }
public string addresstype { get; set; }
public string name { get; set; }
public string display_name { get; set; }
public Address address { get; set; }
public List<string> boundingbox { get; set; }
public string svg { get; set; }
}
VB.Net
Protected Sub OnSubmit(sender As Object, e As EventArgs)
Dim url As String = String.Format("https://nominatim.openstreetmap.org/search?q={0}&format=json&addressdetails=1&limit=1", HttpUtility.UrlEncode(txtLocation.Text))
ServicePointManager.Expect100Continue = True
ServicePointManager.SecurityProtocol = CType(3072, SecurityProtocolType)
Dim webClient As WebClient = New WebClient()
webClient.Headers.Add(HttpRequestHeader.UserAgent, "/")
Dim json As String = webClient.DownloadString(url)
Dim places As List(Of Place) = JsonConvert.DeserializeObject(Of List(Of Place))(json)
lblLatitude.Text = places(0).lat
lblLongitude.Text = places(0).lon
End Sub
Public Class Address
Public Property historic As String
Public Property house_number As String
Public Property road As String
Public Property neighbourhood As String
Public Property suburb As String
Public Property borough As String
Public Property city As String
<JsonProperty("ISO3166-2-lvl4")>
Public Property ISO31662lvl4 As String
Public Property postcode As String
Public Property country As String
Public Property country_code As String
End Class
Public Class Place
Public Property place_id As Integer
Public Property licence As String
Public Property osm_type As String
Public Property osm_id As Integer
Public Property lat As String
Public Property lon As String
Public Property [class] As String
Public Property type As String
Public Property place_rank As Integer
Public Property importance As Double
Public Property addresstype As String
Public Property name As String
Public Property display_name As String
Public Property address As Address
Public Property boundingbox As List(Of String)
Public Property svg As String
End Class
Screenshot