Although it works pretty fast, it's slower than accessing a local binary file or a local database due to the network latency overhead.Īnyway, we are talking about "1 second of waiting time" in case of a web-service versus "less than 1 second waiting time" in case of local storage access, which is not a mission-critical constraint in many cases.Īll in all, it is good to know, that there is an easy, fast and cheap way to start using the IP address to location conversion with help of a Web service. The obvious limitation of the Web service approach is the request speed. The only thing to care about is when you send cross-domain AJAX requests you maybe restricted if you do not send the right set of CORS headers from the server. Since the Web service call can return the response in the JSON format, which is native JavaScript notation, it's not so hard to make a call and process the result. It can potentially be used not only on server-side with help of PHP, but also at client-side by JavaScript. You are just ready to go.Īnother advantage of the Web service comes from its nature. The advantage of this approach is that there is no need to install anything or access any kind of a local file or database. The service can be currency exchange rate for a given date and currency, or, as in our example, you can send an IP address as text and get the location information. In short, a Web service is a URL you call with a list of parameters and get results back, usually in a format like XML or JSON. So in our example we are going to use this approach to make the calls to the Web service. This will output "Hello world" of course. There is an easy way to run single PHP commands from command line: you just need to run PHP interpreter with "-r" flag like this: php -r 'echo "Hello world" ' The Web service access has a paid version, but even the free demo version is enough to play with this solution. To cut the long story short, it can be done with PHP one-liner (one line of code that solves the task) if we just query IP2Location Web service. I don't have any database or IP2Location binary file installed on my laptop that I could query, and I want to check if my current IP address can be converted to a location. Let's use this example to check how easy is the IP2Location Web service that helps to detect geo location just by the given IP address. For this reason, the IP-based Geolocation will be about 99% accurate at theĬountry level while the accuracy of State and City may be at much less accurate level somewhere around 50% range.I am writing this article from Borispol airport which is close to Kiev city (Ukraine). Other ISPs may be serving smallerĪreas, and some ISPs create subnetworks to serve their customers in smaller regions. Since many Internet users are getting their dynamic IP addressįrom their ISP, and most ISPs serve their customers in multiple regions causing Geolocation lookup to be accurate to the region they serve.įor example, AT&T in the United States serve their customers in entire USA and the accuracy may be limited to the Country level. The data come from a few IP-Based Geolocation providers,Īnd their accuracy varies depending on how quickly they update their database when changes occur. The Geolocation lookup tool provided on this page is an estimate of where the IP address may be located.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |