Hi ahmadsubuhanl,
Generate your Geocode API key using the link.
https://geocode.maps.co/
Using the API
Url to get latitude and longitude using Address.
https://geocode.maps.co/search?q=address&api_key=API_Key
Url to get Address from latitude and longitude.
https://geocode.maps.co/reverse?lat=latitude&lon=longitude&api_key=API_Key
Refer below sample code.
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 System.IO;
using Newtonsoft.Json;
VB.Net
Imports System.Net
Imports System.Web
Imports System.IO
Imports Newtonsoft.Json
Code
C#
protected void OnSubmit(object sender, EventArgs e)
{
string aPIKey = "API_KEY";
string geocodeUrl = string.Format("https://geocode.maps.co/search?q={0}&api_key={1}&format=json", HttpUtility.UrlEncode(txtLocation.Text), aPIKey);
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(geocodeUrl);
using (WebResponse response = request.GetResponse())
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
string result = reader.ReadToEnd();
List<Place> places = JsonConvert.DeserializeObject<List<Place>>(result);
lblLatitude.Text = places[0].lat;
lblLongitude.Text = places[0].lon;
}
}
}
public class Place
{
public int place_id { get; set; }
public string licence { get; set; }
public string osm_type { get; set; }
public object osm_id { get; set; }
public List<string> boundingbox { get; set; }
public string lat { get; set; }
public string lon { get; set; }
public string display_name { get; set; }
public string @class { get; set; }
public string type { get; set; }
public double importance { get; set; }
}
VB.Net
Protected Sub OnSubmit(ByVal sender As Object, ByVal e As EventArgs)
Dim aPIKey As String = "API_Key"
Dim geocodeUrl As String = String.Format("https://geocode.maps.co/search?q={0}&api_key={1}&format=json", HttpUtility.UrlEncode(txtLocation.Text), aPIKey)
Dim request As HttpWebRequest = CType(HttpWebRequest.Create(geocodeUrl), HttpWebRequest)
Using response As WebResponse = request.GetResponse()
Using reader = New StreamReader(response.GetResponseStream())
Dim result As String = reader.ReadToEnd()
Dim places As List(Of Place) = JsonConvert.DeserializeObject(Of List(Of Place))(result)
lblLatitude.Text = places(0).lat
lblLongitude.Text = places(0).lon
End Using
End Using
End Sub
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 Object
Public Property boundingbox As List(Of String)
Public Property lat As String
Public Property lon As String
Public Property display_name As String
Public Property [class] As String
Public Property type As String
Public Property importance As Double
End Class
Screenshot
Note: API endpoints return JSON data by default.
For different formats, append &format={format}
{format} is one of the following: xml, json, jsonv2, geojson, geocodejson.