Get a city with the Cloudflare IP geolocation - geolocation

In the docs, I see I can get a Country, but is there a way to get a bit more, like a subdivision or even a city, from Cloudflare?

Cloudflare users on Business or Enterprise plans have access to more granular geolocation fields in the Ruleset Engine (which powers many different Cloudflare features)
ip.geoip.subdivision_1_iso_code: Represents the ISO 3166-2 code for the first level region associated with the IP address.
ip.geoip.subdivision_2_iso_code: Represents the ISO 3166-2 code for the second level region associated with the IP address.
See this documentation page for the full list.

Related

Convert longitude/latitude to country, city in MaxMind

I am using MaxMind GeoIP2 database to determine client's location (longitude, latitude, city, country) based on IP address.
For that I'm using Python library geoip2 and local GeoLite2-City.mmdb database.
In order to get more precise result I want to use HTML5 geolocation in addition which returns only coordinates of the client.
I want to use the already existing MaxMind local database to get the country and city based on the coordinates from HTML5 method.
Is it possible and how?
You might want to check the services they provide (I did not see them having what you are looking for), and then maybe contecting their support for more assistance.
Anyways, you could easily use any Reverce Geocoding service which provides REST interface for determining the country (and actuall more accurate address), thus I would suggest you reconsider the requirements on utilizing the original provider for the purpose.
If for some reason you need to have a certain Geo-location for all users in same city, then after reverce geocoding the city & country, use those values (without any actual street address) with geocoding service to get the 'center' of the city.

Geolocation and getting a city from an input address (Rails)

The app I'm building needs to be able to match up users to events based on the city/town they're in. I'm still relatively new to Rails and completely new to Geolocation and using locations in an app. I'd figured on a design where users have one or many cities, and events would have one city which I'd hoped to extract without specifically asking the user for it, by getting it from the event address entered.
Mostly to provide some outside checking to help get the address entered correctly and consistently, but also to show a map, I installed this jquery address picker (https://github.com/sgruhier/jquery-addresspicker). Unfortunately the data returned by Google doesn't include a city but a "locality" or an "administrative area" that doesn't correlate reliably to city names. The localities being returned are more like what we in my home town would call "suburbs". What I need to procure is a city so I can allow users to search all events in their city rather than just the ones in their suburb.
Can anyone offer advice on how I could go about doing this? Many thanks.
Edit: Should maybe add that I'm wanting to do geocoding client-side so I don't run into problems with Google Maps limits or have to pay for geocoding etc.
There are some gems that provide you with that and may others geo related features, like calculating distances.
Here are the 2 most famous: https://github.com/alexreisner/geocoder and https://github.com/imajes/geokit
In the future I highly recommend you to head to https://www.ruby-toolbox.com/ to see what is available as a gem already and see what is the most popular at the moment.
For raw address info, use Google Maps API Reverse Geocoding which accepts lat/lon inputs and returns street address components. Modern browsers support location awareness (geolocation), with user permission, and will give you a lat/lon that "tends to be close" to where the browser is. That will probably get you a correct city/town in most cases.
The maps API is part of Google's broad suite of API tools -- there are gems that handle any Google API (well, most of them), or check out Google Maps for Rails, which will at the very least give you a good head start on how to use the API.
But if you're looking to validate postal code, this method will come up short, since the location awareness will vary in accuracy depending on browser, device (more accurate for mobile), the connection, population density, network coverage, and so on. Also, calling the
If you can get GPS-accurate lat/lon then it will be much more accurate ... except in some cases like in large cities, a single building will have its own postal code, so a few feet one way or the other might matter.

Display content based on location

How do I go about displaying content based on a users location ? For ex. If somebody accesses the site from the New York , I would like to display New York Hotels . However if somebody accesses the site from Chicago , I would like to display Chicago hotels.
You're looking for a Geoloction database which would give you access to the typical IP ranges for the countries/cities you need to flag.
This is not absolute or completely trustworthy information though. Country level geo-location is mostly effective but anything like city/state/zip code level information should be treated with great caution.
I've worked with major multinational media providers using expensive paid services and discovered that the information in these databases is a very long way from correct and that users individual circumstances often prevent geo-location from being effective.
e.g. Virgin and East Coast trains in the UK use T-Mobile Germany as their onboard internet provider so you appear to be in Germany to many sites and payment processors.
There are quite a few free geolocation databases, MaxMind springs to mind (though this is not a recommendation of their service).
You can find some thoughts on implementing geo-location here
You need some database/api with information about hotells in different locations, then you need to now where the visitor is.
You can use something like Travel/Hotel API's? to find hotells.
And for finding the location of your visitor you can use something like http://www.hostip.info/use.html
or you can use HTML5 geolocation api example http://html5demos.com/geo . The bad thing with the html5 geo api is that the user need to accept before you get their location.
Remember that there is no guaranty that the location is correct...
This is the exact reason I created wpgeocode. WPGeocode is a free plugin for wordpress that enables publishers to customize content based on reader location. Check out the plugin at the support site at http://www.wpgeocode.com
The plugin enables shortcodes that can be placed in your posts or pages. There are many conditional shortcodes such as [wpgc_is_country_code country_code="US"] for this exact purpose. Simple open the shortcode, specify the target country_code and provide the content to be displayed if the reader is visiting from that specific country.
Visit http://www.wpgeocode.com/shortcodes for a complete listing - here are a few:
[wpgc_is_city_and_state city=”Yardley” state_code=”PA”]
[wpgc_is_ip” ip=”xx.xx.xx.xx”]
[wpgc_is_ips” ip=”xx.xx.xx.xx,aa.bb.cc.dd”]
[wpgc_is_not_ip” ip=”xx.xx.xx.xx”]
[wpgc_is_not_ips” ip=”xx.xx.xx.xx,aa.bb.cc.dd”]
[wpgc_is_city” city=””]
[wpgc_is_cities” cities=”city one,city two,city three”]
[wpgc_is_not_city” city=””]
[wpgc_is_not_cities” cities=”city
one,city two,city three”]
[wpgc_is_nearby”] – Uses the value you
specify in the Nearby Range setting from the administrative panel
[wpgc_is_not_nearby”]
[wpgc_is_within” miles=”10″]
[wpgc_is_within
kilometers=”12″]
[wpgc_is_country_name” country_name=””]
[wpgc_is_country_names” country_name=”United States,Egypt,Albania”]
[wpgc_is_country_code” country_code=””]
[wpgc_is_country_codes”
country_codes=”US,GB,AZ”]
[wpgc_is_state_code” state_code=””]
[wpgc_is_state_codes” state_codes=”PA,NJ,TX”]
[wpgc_is_not_country_name” country_name=””]
[wpgc_is_not_country_names” country_names=”United
States,Egypt,Albania”]
[wpgc_is_not_country_code” country_code=””]
[wpgc_is_not_country_codes” country_codes=”US,GB,AZ”]
[wpgc_is_not_state_code” state_code=””]
[wpgc_is_not_state_codes”
state_codes=”PA,NJ,TX”]
dotCMS offers the ability to geolocate content OTB (disclaimer, I work for them). You can see a demonstration that displays news content based on the user's location onthe demo site:
It is pretty easy to setup and use. Any type of content can be geolocated and the content can be accessed through the RESTful API. Under the covers, the Geolocation queries are handled natively via Elasticsearch.
Example:
http://demo.dotcms.com/demos/content-geolocation
Docs:
http://dotcms.com/docs/latest/es-geolocation-queries

Resolve city code from user input

There are a lot of geocode services out there (like http://geo-autocomplete.googlecode.com/svn/trunk/demo/ui.demo.html for example) where user can write a location (or part of it) and it will be resolved to real existing location.
There is also a lot of info provided with the search result (like country ISO code, coordinates, etc..), but none of the services seem to provide country and city code.
What I mean is a code used to phone to certain are. For example Country code for Germany will be 49 and for city of Dusseldorf will be 211.
Is there any service, where I can get this info from the user input. Or is there any way to combine the two. For example I get city name from google geocode service and the try it on some city codes database. If yes, can anyone please provide me with links.
You can use for instance Yahoo's GeoPlanet. For more elaboration on services to solve your problem you might want to check out this answer on gis.stackexchange.com, which seems to cover the kind of service you need.

Getting Country, State, City, PostalCode from GPS coods

I am using ipinfodb.com to get geolocation info for IPs, but it only gives postal codes for US addresses.
I am also getting GPS coods from mobile devices, but I need to get more useful information from these GPS coods, that is the country, state, city and postalcode of that GPS coods.
Two questions, 1) is there a more comprehensive database than ipinfodb.com that will get postal codes for IPs outside of the US? 2) is there a way to get address information from GPS coods (including places outside the US).
MaxMind offers a free version of their GeoCity database.
http://www.maxmind.com/app/geolitecity
Also, there is an open source, free-to-use web service at:
http://hostip.info
Both should provide comprehensive location data.
Google does reverse Geocoding but IIRC, according to the Terms and Conditions, the results are to be used only in a Google Map.

Resources