5 ms·
If you don't want to do this yourself, you can actually just get Cloudflare to do it for you for free using a simple Worker since all Cloudflare requests contai
by louison11 3y ago
If you don't want to do this yourself, you can actually just get Cloudflare to do it for you for free using a simple Worker since all Cloudflare requests contain approximate IP location information.
You can also just send a request to my URL (Cloudflare Worker operated - so it should have global low latency): https://www.edenmaps.net/iplocation https://www.edenmaps.net/iplocation
Use it for small applications, I don't mind. Just don't start sending me 10M requests per day ;-)
- deleted 3y ago[deleted]
- Aachen 3y agoOr you download an IP database rather than sharing with a third party which IP address is likely connecting to your service with a third party
- oh_come_on 3y ago[dead]
- tiffanyh 3y agoThis is excellent! Would you mind open sourcing the code for that?
- louison11 3y agoThis is the code running this endpoint: export function onRequest(context) { return new Response(JSON.stringify([parseFloat(context.request.cf.longitude), parseFloat(context.request.cf.latitude)]), {headers: {"Content-Type": "application/json;charset=UTF-8"}}) } This is a function on Cloudflare Pages (which is just a different name for Cloudflare Workers). Minor adjustment needed for Workers (get rid of "context", I believe)
- emadda 3y agoDoes anyone know how accurate Cloudflare geolocation is (for workers requests)?
- banana_giraffe 3y agoAs accurate as MaxMind[1], since that's what they use [2]. In my experience, it's reasonably accurate for the US, less so for other countries. MaxMind publishes some accuracy data which might be an interesting starting point [3] That said, for any analytics use cases of this data, be aware that MaxMind will group a lot of what should be unknowns in the middle of a country. Or, in the case the US now, I think they all end up in the middle of some lake, since some farm owners in Butler County, Kansas got tired of cops showing up and sued MaxMind. It can cause odd artifacts unless you filter the addresses out somehow. 1 https://developers.cloudflare.com/support/network/configuring-ip-geolocation/ https://developers.cloudflare.com/support/network/configurin... 2 https://www.maxmind.com/en/geoip-demo https://www.maxmind.com/en/geoip-demo 3 https://www.maxmind.com/en/geoip2-city-accuracy-comparison https://www.maxmind.com/en/geoip2-city-accuracy-comparison
- matwood 3y agoYeah, MaxMind is the best I have used with caveats. You need to update it frequently, and you need to allow for overrides.
- reincoder 3y agoI work for IPinfo and we do ping based geolocation. The best thing you can do to verify geolocation accuracy is the following: - Download a few free IP databases - Generate a random list of IP addresses - Do the IP address lookups across all those databases - Identify the IP address that can be pinged - Visit a site that can ping an IP address from multiple server - Sort the results by lowest avg ping time Then check where the geolocation provider is locating the IP address and what is the nearest server from there.
- noizejoy 3y agoOn one hand, I love that there’s some good alternatives in the geolocation space, but misleading geolocation precision can lead to very undesirable side effects[0]. [0] https://www.theguardian.com/technology/2016/aug/09/maxmind-mapping-lawsuit-kansas-farm-ip-address https://www.theguardian.com/technology/2016/aug/09/maxmind-m...
- hotgeart 3y agoLocated 100km from the Somali coast... I'm in Brussels, Belgium, thx for protecting my privacy :D
- louison11 3y agoThe result is [lon, lat]. You’ve most likely copied it onto Google maps, which works with [lat, lon]. Believe it or not, the industry still hasn’t come up with a standard order.
- mrklol 3y agoYou could also just return a json with lat and lon as fields so nobody is getting confused. {lat:5, lon:7}
- somedude895 3y agoGot me to within 1km, that's pretty crazy
- helmchenlord 3y agoSame here. Scaring.
- carstenhag 3y agoI'm in Munich. Cloudflare tells a position that is 730km to the north in a random forest.
- louison11 3y agoYou've inverted lat, lon.
- carstenhag 3y agoNo, the other one was in the ocean