Using JS, on a wab browser. NOT native or phone-gap or that sorts, Any one knows how to find a mobile users "phone country code" by his/hers location? not looking to know the number or any thing like that, just getting the phone country code from the device position.
Native developers has that API, why not web?
googles GeoName API doesn't return this from what i read. and i couldn't find any API for getting the country phone code by geolocation.
It's weird that i couldn't find any question same to this nowhere.
Using JS, on a wab browser. NOT native or phone-gap or that sorts, Any one knows how to find a mobile users "phone country code" by his/hers location? not looking to know the number or any thing like that, just getting the phone country code from the device position.
Native developers has that API, why not web?
googles GeoName API doesn't return this from what i read. and i couldn't find any API for getting the country phone code by geolocation.
It's weird that i couldn't find any question same to this nowhere.
Share Improve this question asked Feb 16, 2016 at 16:30 ErezErez 1,9535 gold badges29 silver badges59 bronze badges 2- Try with the HTM5 Geolocation: w3schools./html/html5_geolocation.asp – ryan0319 Commented Feb 16, 2016 at 16:40
- 10x, geolocation returns lots of things, i'm taking the long and lat from there but from what i've read it doesn't return the phone code number (that 3 digits number, in most cases, that es before the phone number ), i need to get that from some other api and just can't find the right one – Erez Commented Feb 16, 2016 at 16:45
1 Answer
Reset to default 3All you need to do is to get clients country name and then match it to a database containing the country phone.
Here is the database: https://gist.github./adhipg/1600028
And here is the code to get the clients country:
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
$.getJSON('http://ws.geonames/countryCode', {
lat: position.coords.latitude,
lng: position.coords.longitude,
type: 'JSON'
}, function(result) {
alert(result.countryName);
});
});
}
If you don't want to use a username for the last piece of code you can you this code:
$.get("http://ipinfo.io", function(response) {
console.log(response.city, response.country);
}, "jsonp");