Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Searchforarticles,questions,tips
articles Q&A forums lounge
i have tried using some google api but i dont require google map, as i have to input the latitude and longitude to get the location
name and timezone. i also used the Microsoft Exchange webservice dll that provides TimeZoneType which gives
gettimezonebycordinates which is not successful so i request to please help me in this regard by giving some links or suggestion
that help me to work on this.
Add a Solution
Comments
in code behind i have written this code and there is no reference or namespace for rest client class. i herd there is REstSharp library for
.net in github but did not help me out to go further. mainly i need the timezone and location name based on latitude and longitude, but
here if i use this code with some library do u think i will get what i have mentioned
visit here...
HowtofindLocationbasedonLatitudeandLongitudevalues[^]
Comments
https://www.codeproject.com/Questions/758354/gettimezoneandlocationnameusinglatitudeand 2/8
5/9/2017 [Solved]gettimezoneandlocationnameusinglatitudeandlongitudeinC#CodeProject
class Program
{
const string GOOGLE_API = "https://maps.googleapis.com";
const string GOOGLE_TIMEZONE_REQUEST =
"maps/api/timezone/xml";
// Pensacola, FL
const double LATITUDE = 27.172079;
const double LONGITUDE = 78.036618;
// ****************************************************** Main
time_zone = get_time_zoneLATITUDE,
LONGITUDE,
DateTime.Now;
//this will take timezone object i.e timezone id to give the current date time
DateTime timeUtc = DateTime.Now;
string s = time_zone;
TimeZoneInfo cstZone = TimeZoneInfo.FromSerializedStringtime_zone;// issue is here when debug says null in the timezone object
DateTime cstTime = TimeZoneInfo.ConvertTimeFromUtctimeUtc, cstZone;
Console.WriteLine"Current date time of the given timezone received from latitude and longitude" + cstZone;
Console.WriteLine"Timezone" + time_zone;
Console.Write"Press any key to exit";
Console.ReadKey;
}
// ********************************************* get_time_zone
try
{
client = new RestClientGOOGLE_API;
request = new RestRequestGOOGLE_TIMEZONE_REQUEST,
Method.GET;
location = String.Format"{0},{1}",
latitude,
longitude;
time_since_midnight_1970 = date.Subtract
new DateTime1970, 1, 1, 0, 0, 0;
time_stamp = time_since_midnight_1970.TotalSeconds;
request.AddParameter"location", location;
request.AddParameter"timestamp", time_stamp;
request.AddParameter"sensor", "false";
response = RestResponseclient.Execute
request;
if response.StatusDescription.Equals"OK"
https://www.codeproject.com/Questions/758354/gettimezoneandlocationnameusinglatitudeand 3/8
5/9/2017 [Solved]gettimezoneandlocationnameusinglatitudeandlongitudeinC#CodeProject
{
XmlNode node;
XmlDocument xml_document = new XmlDocument;
xml_document.LoadXmlresponse.Content;
node = xml_document.SelectSingleNode
"/TimeZoneResponse/time_zone_name";
if node != null
{
time_zone = node.InnerText;
}
}
}
catch Exception ex
{
time_zone = "In error";
}
return time_zone;
}
}
}
the issue with this not able to take timezone object that has timezone id to get current date time and also not able to get location name on
basis of this.PLZ help me regarding this.
I am going to guess that the latitude and longitude you supplied to the Google API was somewhere in India. Thus the UTC+6. If by "current
format" you mean some other time zone, then see Converting Times Between Time Zones.
https://www.codeproject.com/Questions/758354/gettimezoneandlocationnameusinglatitudeand 4/8
5/9/2017 [Solved]gettimezoneandlocationnameusinglatitudeandlongitudeinC#CodeProject
In your code you are using JSON retrieval. This is fine for Javascript but in C# it raises difficulties. I'd suggest using the XML
retrieval.
https://www.codeproject.com/Questions/758354/gettimezoneandlocationnameusinglatitudeand 5/8
5/9/2017 [Solved]gettimezoneandlocationnameusinglatitudeandlongitudeinC#CodeProject
Comments
Preview
https://www.codeproject.com/Questions/758354/gettimezoneandlocationnameusinglatitudeand 6/8
5/9/2017 [Solved]gettimezoneandlocationnameusinglatitudeandlongitudeinC#CodeProject
2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults
are not welcome.
This content, along with any associated source code and files, is licensed under The Code Project Open License CPOL
CodeProject, 503250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 4168498900 x 100
https://www.codeproject.com/Questions/758354/gettimezoneandlocationnameusinglatitudeand 7/8
5/9/2017 [Solved]gettimezoneandlocationnameusinglatitudeandlongitudeinC#CodeProject
https://www.codeproject.com/Questions/758354/gettimezoneandlocationnameusinglatitudeand 8/8