admin管理员组文章数量:1429676
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");
本文标签: jqueryHow to find a user phone country code form current location using javascriptStack Overflow
版权声明:本文标题:jquery - How to find a user phone country code form current location using javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745481980a2660214.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论