How to get current city name?

Posted by Gow.Net under ASP.NET on 6/25/2013 | Points: 10 | Views : 2354 | Status : [Member] | Replies : 3
Hi all

When user open my site i need to get current city name and disply how?

gowthaman8870226416


Responses

Posted by: Learningtorise on: 6/25/2013 [Member] Starter | Points: 25

Up
0
Down
//this line is to check the clien ip address from the server itself
string IP = Request.ServerVariables["REMOTE_ADDR"];

//Initializing a new xml document object to begin reading the xml file returned
XmlDocument doc = new XmlDocument();

//NOTE: www.showmyip.com only allows 199 request/day
//as a free call, for more requests u could register with them
/////////////////

//send the request to www.showmyip.com sending the ip as a query string
//and loads the xml file in the document object
doc.Load("http://www.showmyip.com/xml/?ip=" + IP);

//begin finding the country by tag name
XmlNodeList nodeLstCountry = doc.GetElementsByTagName("lookup_country");

////begin finding the city by tag name
XmlNodeList nodeLstCity = doc.GetElementsByTagName("lookup_city2");

//concatinating the result for show, u could also use it
//to save in data base
IP = "Country :" + nodeLstCountry[0].InnerText +
" -- City :" + nodeLstCity[0].InnerText + "" + IP;
Response.Write(IP);

//this is my header that I love
Page.Header.Title = "I am Indian before anything";

http://hashtagakash.wordpress.com/

Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: aswinialuri-19361 on: 6/25/2013 [Member] Starter | Points: 25

Up
0
Down
Hi gowtham ,
refer this i think it will be useful to you

http://www.aspdotnet-suresh.com/2013/01/javascript-get-user-details-ip-address.html

Mark as Answer if it helps you
Thanks&Regards
Aswini Aluri

Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jitendrasoft09 on: 6/25/2013 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hi,
It is nice question, Hope all are trying well, We have another approach to get city name wherever we will be in the world, so we need some api to do globally.
Maxmind provides the js api to search city name globally, plz refer below link for more information.

http://j.maxmind.com/app/geoip.js



Jitendra Kumar
If my post helps you, plz mark as an answer.

Gow.Net, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response