Hi Irushh,
Refer the below sample code. Here i have used Newtonsoft.Json library.
Use the DLL from below link and add reference to your project or website.
Newtonsoft Json
You need to import following namespaces.
C#
using Newtonsoft.Json.Linq;
using System.Web.Services;
VB.Net
Imports Newtonsoft.Json.Linq
Imports System.Web.Services
HTML
<div>
<asp:TextBox ID="TextBox1" runat="server" />
</div>
<div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?libraries=places&sensor=false&key=AIzaSyCI2rrQ6FeYu6JvfehofKYLLKxkDxem78o"></script>
<script type="text/javascript">
google.maps.event.addDomListener(window, 'load', function () {
var places = new google.maps.places.Autocomplete(document.getElementById('<%= TextBox1.ClientID %>'));
google.maps.event.addListener(places, 'place_changed', function () {
var place = places.getPlace();
var latitude = place.geometry.location.lat();
var longitude = place.geometry.location.lng();
var weburl = "https://maps.googleapis.com/maps/api/timezone/json?location=" + latitude + "," + longitude + "×tamp=" + (Math.round((new Date().getTime()) / 1000)).toString() + "&sensor=false";
$.ajax({
type: "POST",
url: "Default.aspx/GetTimeZoneName",
data: "{Url: '" + weburl + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (r) {
alert(r.d);
}
});
});
});
</script>
</div>
C#
[WebMethod]
public static string GetTimeZoneName(string Url)
{
string timeZoneName = "";
System.Net.WebClient client = new System.Net.WebClient();
byte[] response = client.DownloadData(Url);
string content = System.Text.Encoding.ASCII.GetString(response);
JObject obj = JObject.Parse(content);
try
{
timeZoneName = obj.SelectToken("timeZoneName").ToString();
return timeZoneName;
}
catch (Exception ex)
{
timeZoneName = ex.Message;
}
return timeZoneName;
}
VB.Net
<WebMethod()> _
Public Shared Function GetTimeZoneName(Url As String) As String
Dim timeZoneName As String = ""
Dim client As New System.Net.WebClient()
Dim response As Byte() = client.DownloadData(Url)
Dim content As String = System.Text.Encoding.ASCII.GetString(response)
Dim obj As JObject = JObject.Parse(content)
Try
timeZoneName = obj.SelectToken("timeZoneName").ToString()
Return timeZoneName
Catch ex As Exception
timeZoneName = ex.Message
End Try
Return timeZoneName
End Function
ScreenShot
