How to get User Location in JavaScript / jQuery PHP Website

Solution : 1 The HTML5 geolocation API will get you the user's latitude and longitude (assuming they opt in). If you need ...

How to get User Location in JavaScript / jQuery PHP Website-newvijay

Solution : 1




The HTML5 geolocation API will get you the user's latitude and longitude (assuming they opt in). If you need to get info such as the city, country, or postal code, you'll need to use a reverse-geocoding web service. There are plenty of those out there:

    Google
    Bing
    etc

So take your pick... just make sure to look at the terms & conditions and be sure you won't be in violation once the site goes live.

You should be able to find code samples by googling around a bit, it's a fairly common use case. The steps will be:

    Get the user's lat/lng with your existing code.
    Make an AJAX (JSONP) call to request the reverse-geocode (use your Geocode provider to figure out what URL to use. eg, for Google it is like this).

    Parse the JSON response to extract the info you need (country, city).




Solution : 2


Try this code using the hostip.info service:

$country=file_get_contents('http://api.hostip.info/get_html.php?ip=');
echo $country;

// Reformat the data returned (Keep only country and country abbr.)
$only_country=explode (" ", $country);

echo "Country : ".$only_country[1]." ".substr($only_country[2],0,4);


Solution : 3

MaxMind GeoIP is a good service. They also have a free city-level lookup service.

COMMENTS

Name

Android Apple Apps Gadget Gaming How Tos Laptops Latest Latets news Linux Microsoft New Movies New phones New Tricks Nokia Offers PC Programing ROMs Root Softwares Solution SONY Symbian^3 Themes TOP 10 HD iPad 2 Games Whatsapp
false
ltr
item
New Vijay: Leaked Online Loot and Offers : How to get User Location in JavaScript / jQuery PHP Website
How to get User Location in JavaScript / jQuery PHP Website
http://1.bp.blogspot.com/-hVwvUPPsCEQ/VZdNCGA013I/AAAAAAAAD74/NamOYo3IKs0/s640/How%2Bto%2Bget%2BUser%2BLocation%2Bin%2BJavaScript%2B%2BjQuery%2BPHP%2BWebsite-newvijay.png
http://1.bp.blogspot.com/-hVwvUPPsCEQ/VZdNCGA013I/AAAAAAAAD74/NamOYo3IKs0/s72-c/How%2Bto%2Bget%2BUser%2BLocation%2Bin%2BJavaScript%2B%2BjQuery%2BPHP%2BWebsite-newvijay.png
New Vijay: Leaked Online Loot and Offers
http://newvijay.blogspot.com/2015/06/how-to-get-user-location-in-javascript.html
http://newvijay.blogspot.com/
http://newvijay.blogspot.com/
http://newvijay.blogspot.com/2015/06/how-to-get-user-location-in-javascript.html
true
7835349826098902170
UTF-8
Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy