My user model is using geokit to find the address from an ip address. How do I let the user select a different country, state or city? I have checked all the documentation and I can't figure out how to retrieve a list of countries, states or cities.
Your question isn't 100% clear but you may be trying to do something Geokit isn't designed for.
Geokit basically does one thing: it takes an IP address, or a physical address, and gives you the lat/long. When you install it as a Rails plugin, you can geocode your models (usually with a street address) and it adds some useful stuff to your model classes. These extra things let you compute distances between your model objects.
AFAIK, you can't get a list of countries from Geokit. On my projects I've either used one of the free online lists, exported a list from another application, or subscribed to a service.
Related
I have 2 models one for customer and one for vendor, I'm trying do make a site that when customer sign in, they can search using their ip address and search for near by location, the result will be some vendor with nearby address. So far, I plan to use geocoder and gmap4rails gem. I'm still not sure how I would store the vendors address using geocoder so that when the customer search, the correct result will be presented. Can some one give suggestion on how to design this feature?
Since you're just looking for a "design" and not code, I can just outline the broad steps:
ip form submitted =>
lookup geodata for local businesses =>
store geodata in "vendor" model =>
The only non-standard rails part of this is the geo-lookup.
There are multiple ways to do this, most certainly using some external API. I don't think the geocoder or gmap4rails gems have this functionality.
While you're probably using gmap4rails for your view layer, I'm not sure you'll need the geocoder gem if you're using a different service to perform the vendors lookup. This external service might accomplish the same thing.
As for which external service to use: I'd look at Yelp or one of Google's APIs.
In response to your comment:
When a user logs in, you'll probably want to set a session cookie for them.
There is no reason to have the ip form "belong to" any user. When the form is submitted, you'd be able to look up the current signed in user from the controller action which is hit when the form is submitted.
If you store vendor data in your database, you can then present the data in the view.
If these concepts are new to you, I'd recommend going through a detailed tutorial of Rails.
I'm trying to find a good way to store and connect users based upon their city.
Location names can come from a variety of places, including facebook connection, ip lookup, and event user input.
I want to be able to input an address and get back a unique location ID. NY and New York will be understood as the same, but cities in two locations are not understood as the same.
Can I use facebook's location databse for this? Or google's location api? Or would it be better to roll my own, doing searches and filtering to consecutively narrow down results, from country to state to city, while normalizing for abbreviations, internationalizations, and typos? Or is there a plugin that will do this for me?
Thanks!
I would use https://github.com/alexreisner/geocoder . In general you have to add latitude and longitude to your model (they will identify location) and then specify which field should be geocoded. It allows you to store locations from different sources: city name, ip address and others. There are many configuration options (eg. you can specify Geocoding Services). Check out the gem readme page for all the details.
in my asp.net mvc app i have a survey Model that can be created by anyone. Moreover, i want people from specific part of world to participate (vote) in the survey. It is easy job if i know the location (it could be city, country or state etc.). i want to add this location restriction at the time of survey creation (i.e user could tell that people of Islamabad or punjab or Pakistan) could vote or fill out this survey form. Moreover, i want to add that location restriction is applicable (or expected) for small number of surveys (5 percent at most) so how to most efficiently implement this functionality.
You could do this a couple of ways:
Determine where the user is from based on a previous question asking their location. Not bullet proof as the user could easily say they are from somewhere they are not.
Obtain an IP -> Country mapping list that will provide you a lookup of the customer's IP address vs. their location. You would restrict based on this.
You can figure out someone's location using IP address. There are many services out there that offer IP address location. They will give you an approximation of the users location based on that.
Here is an example of the service:
You can also get their location using HTML5 geolocation features.
For your case using IP address is probably good enough. The HTML5 option is nice because if the user doesn't have a GPS device on their system it eventually falls back to using IP address location.
In order to get a users IP address in ASP.NET you can use
Request.Servervariables("REMOTE_ADDR")
I have a client who has a requirement that they can't sell particular products 'outside the United States'.
They'd prefer that users can see the site, but when they try to checkout present a message indicating they are outside the United States.
Their site is built in Rails 2.3.8.
Check out the GeoIP gem (make sure to read the instructions, you need to download the GeoLiteCity or GeoLiteCountry database in order for it to work). It uses MaxMind's GeoIP database and can give you the country (or city, in the case of the city database) of an IP address, with some accuracy. There is a commercial database with better accuracy available, which I would recommend for your use case.
However, be advised that this is by no means a definitive solution. Some customers will be turned away wrongfully, and some will be able to order even though they should not. Things like satellite connections, proxy servers and VPN services make IP location impossible, and no database is 100% complete or correct.
What you're looking for is some kind of rough geolocation. One way to get this is to query a DNS zone designed specifically for this; one such zone is described at http://countries.nerd.dk.
I am from Ukraine. And when a particular US shop doesn't want to sell products overseas it usually specifies in the policy/faq/etc that only US bank issued payment cards are accepted.
That seems for me the best solution to solve: "can't sell particular products 'outside the United States'. "
As there are package/mail/freight forwarding companies which can be used by a potential client of that customer though residing outside US but whom the customer won't have to ship directly. That customer would still benefit from those sales but are freed from dialing with burden associated with overseas shipping.
And when you will solve it with geolocation, that customer would still be able making additional money, when people would still be using the site through different kind of proxies, if that customer will be worth it. :)
You can use their data that you pull into your database to check the user's IP address. http://www.ipligence.com/geolocation/ (you still have to worry about proxying)
I would also check where your shipping it to (checking addresses like suggested above), also check the card address with the card backer like VISA, etc..
And suggested above, your money processing agent shouldn't allow any transactions from outside the U.S. on particular items (if possible)
But I did read your statement SOME products may not be allowed to be sold outside the U.S. So you'll need a way to mark those products in your system and then let the user know they are unable to purchase those items, but continue on with others in the cart.
You could use a Rack Middleware, but it will require that you fork it on Github first.
https://github.com/roja/rack-geo
At the moment this project gives you City and Organisation names based on the IP address of the computer making the request - you need Country Code too.
You could add it to the code relatively easily here: https://github.com/roja/rack-geo/blob/master/lib/rack/geo.rb
You could then set a Rack environment variable to indicate if the request is from the USA, in the call method:
Rack::Request.new(env)["born"] = "...in the USA"
Add it to your config file:
config.middleware.use Rack::Geo
And then in your controller you can test if the request has this environment variable set appropriately and redirect to a 'sorry you must be from the USA' page:
if params['born'] == "...in the USA"
redirect_to "/not_from_round_here"
end
Bear in mind that IP address sniffing is fallible. I often take trains in the UK and end up with Google in German.
A geoip alternative is can be found here: http://humbuckercode.co.uk/licks/gems/geoip/
Uses the maxmind libraries, easy to set up, no schema updates needed, fast
I need to keep track of the users lat/lng/city/country for my application with the following two requirements:
1) Get the users lat/lng/city/country automatically. (This is easy, I can use the ip or if they have a browser that supports geolocation, even better).
2) The user is allowed to customize this location (maybe the ip address lookup didn't give an accurate city). The location is a freeform text field (not a dropdown). When the user enters a new location it should be validated against available cities/countries. If it validates against any one of them, select it and then retrieve the latlng for the new location. (This is what I'm having trouble with)
Also to clarify, this is a Rails 3 app using MongoDB. I am looking for either a single API or database that would allow me to do both (1) and (2). Has anyone done anything similar? Looking for some ideas as to how others have done this.
Your question isn't entirely clear as to what problem you are having. In general terms, I would do it like this:
have a Location model that stores location name and coordinates
when the user enters a location, send an Ajax request to look it up
if it's found, set the location in the session
if it isn't found, return a list of similarly named locations (in case there was a typo) and let the user choose one or stick to their input
when they are done with the input, insert a new location if required and store User.location_id.
You could use Google's Geocoding API to look up the coordinates of unknown locations.
I would recommend the Geokit Gem, it does a very nice job of providing a front end for several Geocoding APIs. I highly recommend sticking with Yahoo or Google, just for sheer data integrity issues.
There is a rails plugin, that adds some nice helpers to Activerecord. At the moment the main project is not rails 3 compatible, but there is at least one fork that has updated for rails 3.