IP Geolocation can be performed for both IPv4 and IPv6 addresses. This API can be used to match an IP address with a zip code, country region city, latitude longitude, or other data point. IP Geolocation is typically performed using an API (Application Programming Interface). This process can be used to determine the country, region, city, latitude, longitude, and other information associated with an IP address. Once the file is copied on your Drive, you can use it whenever you want.IP Geolocation is the process of mapping an IP address to a physical location. To enable editing, go to File → Make a copy. Note that the file is in the View only mode. The above functions are included in this sample Google Sheets file. For more detailed information (e.g., city or lat/long), the accuracy drops to even below 50% in some cases. The accuracy is quite high (probably higher than 95% or even 98%). The accuracy of IP geolocation depends on the information you are seeking. Therefore, I have added the necessary description in the parameters and an example, following the approach that was analyzed here. The getIpGeolocationData function will be used directly in the spreadsheet (check the image above). Performs the request and converts the response into JSON.Ĭhecks if the input string is blank, null or undefined. Return the location-related data to the sheet. LocationData = ipData + ', ' + ipData + ', ' + ipData Default case: get a combination of city, region, and country. Return the appropriate data based on the returnType parameter. Declaring the variable that will contain the returned location data. In case of error, return an error message. IpData = isBlank(ip)? getResponseJsonData('') : getResponseJsonData('' + ip) If the IP is empty, the IP of the Google Server storing the spreadsheet will be used. Send the request to the server and return the JSON data. Declaring the variable that will contain the JSON data returned from the request. Gets the location-related data based on the given IP and the return type. * getIpGeolocationData(ip = '', returnType = '') * The location-related data based on the given IP and the return type. null or empty string), a combination of city, region, and country will be returned. * Available options: "GEO", "TIME", "CITY", "ZIP", "REGION", "COUNTRY". * returnType A cell or a string value that has the type of data that will be returned. * This function returns location-related data based on an IP. (blank): a combination of the city name, region name, and country name /* Start of the GAS code.The getIpGeolocationData function provides several return options to the user: We have already seen and used the last two functions in the previous GAS post. Finally, the isBlank function checks if the input string is blank, null, or undefined. The getResponseJsonData performs the request to the server and converts the response into a JSON object. The getIpGeolocationData gets the location-related data based on the given IP and the return type. The GAS code that follows includes three functions. You can see the available data, which we will read using Google Apps Script. The image above demonstrates the response from this API in JSON format. The query limit, I think, is adequate for the typical Google Sheets user. Once this limit is reached, all of the requests will result in HTTP 403, forbidden, until the quota is cleared. The API is limited to 15,000 queries per hour by default. It uses a database of IP addresses associated with cities and other relevant information like time zone, latitude, and longitude. In this example, we will use the API from freegeoip.app, which provides a free IP geolocation API for software developers. It is exactly what services like Google Analytics offer (of course, they do many other things, too). Why might this process be useful? Consider that every website owner wants to know this kind of information for the people who visit their site. The process of IP geolocation involves mapping the IP address to the country, region (city), latitude/longitude, ISP, and other useful things. As we have seen in the past, the (global) IP address of a device is its unique identifier across the internet. IP geolocation is the process of finding associated geographic coordinates (often expressed as latitude and longitude) of an internet-connected computing or a mobile device using digital information, such as an IP address.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |