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")
Related
So the original requirements was that on the launch of the app, the mobile app will get the current location of the user precise to City. Based on the city, the server/app client will give-city related content.
I know it would not be too difficult if I could use the core location service (since you know suspicious (self-concerned) users usually will disable the location service for a not-so-trusting app).
I have searched the web for few hours and get an summary of following solutions where I need your help to decide which one could be my best option or if you have any other better ones.
Using the [NSlocale autoupdatingCurrentLocale]
cons:
a.The explanation of the return value of the call from apple's document: "The locale is formed from the settings for the current user’s chosen system locale overlaid with any custom settings the user has specified in System Preferences." From which I don't understand what is "custom settings the user has specified in System Preferences"
reference link
b. This value could be misleading and not related with user's actual current city/country at all.
comments: I would be appreciated if anybody could explain me how the locale is changed according to user's setting.
Getting the current iPhone TimeZone
NSTimeZone *localTime = [NSTimeZone systemTimeZone];
NSLog(#"Current local timezone is %#",[localTime name]);
cons:
a. same as item b above, because user can always specify rather than let the system auto update the time zone.
b. precision is comprimised, only capital city will be listed.
comments:Not very promising but easy to implement
Using IP based location detection webservice
Based on my reading, the process will involve the app sending a request to a server where the server will record the IP of the request.(Don't think from App itself could get its own IP correctly since it may inside a local network) Based on the IP recorded through some third party service (with a IP db or some other available APIs), it will return the city information back to the client.
cons:
a. I've never implemented such thing, don't know if it is feasible for a mobile app.
b. Even if it is possible, don't know if it is faster than the core location service.
comments: If you know it is possible for a iOS app to do so please let me know.
Please kindly give me any thoughts you have or suggest any better solution if you know.
Thank you very much.
A preventive measure to avoid all your trouble would be to create an app that wouldn't appear 'not-so-trusting' and use core location to get the location. If a user still does not allow your app to know the location and knowing his city is a must, let him select a city from the list of cites for which content is available. Of course this opens up a huge hole allowing use to get the content for ANY city. Only you can decide if this is an acceptable tradeoff for simpler implementation.
If you must know the CITY automatically without core location, the first two options you mentioned, 'locale' and 'time zone' are useless as each of them encompasses large number of cities. Also, as you mentioned they're dependent on user's settings.
So reverse geocoding the IP address of a web service request using GeoIP or some such service is your best bet. You can find a lot of discussion and references for this on the web.
NSlocale can be highly inaccurate. My colleague bought the iPhone from New Zealand (he was studying there). When I am testing his phone to get the locale for language, it still show as New Zealand English.
Using IP is possible. I made a quick search and I found:-
Find IP address in iphone
how to get ip address of iphone programmatically
You might want to take a good read from above links.
I still think using Core Location is the best way to get the location of the user.
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.
Hii,
We want to redirect our users to one of our web pages corresponding to the users city (location based upon the users ip address and using some ip location databases)
My question is, how to make it work fast? for example in website gropoun, whenever the user visits, it instantly takes the user to its city page.
Thanks.
Edit: We are using PHP
Do you want to do this server or client side? If client side (ie, using javascript), you can use one of many geoip services out there. One in particular is Yahoo!'s YGL
http://developer.yahoo.com/yql/
http://developer.yahoo.com/yql/console/?q=select%20City,RegionName,CountryName%20from%20ip.location%20where%20ip%3D'8.8.8.8'&env=store://datatables.org/alltableswithkeys
Also, you can do it server-side using pretty much and language or framework. You could make API or service calls to third party geoip providers, or you can load the data into your database and do your own look up.
http://www.maxmind.com/app/geolitecity
http://ipinfodb.com/ip_database.php
http://ipinfodb.com/ip_location_api.php
You will also need to "default" to a region or zipcode as every IP address can not be determined. For example, one web application that I currently work on has a 95% USA audience, so we default to the geographical center of the country which is 66952.
You should determine user ip from httpRequest afterwards use some kind of database for example geoip
Cache, cache, cache everything. Cache lookups in your IP table, cache the results for individual users in their session or cookies, cache the rendered localization information portion of your pages (or at least the query intensive parts.)
There are more details that could be given, but it all depends on what your bottlenecks are. (After all there's no point in implementing complex caching on the routing side of things if the bottleneck is in rendering localized information because your DB calls take almost half a second to run). I cannot tell you where the bottlenecks in your application are / will be. You'll need to profile it first -- then optimize on the basis of what the profiler tells you.
I have done this for a few clients server-side using the lookup service http://ipinfodb.com/ip_location_api.php.
Just remember to store IP addresses and locations in the database so you do not do redundant lookups. I used the time zone data to determine the visitor's region.
I wish to track a user's country from where my website is accesed .
ex; if a customer from a particular is accessing say america how to trace that the user is actually from america.
Is there any way
What you are talking about is called GeoIP and there are many ways to do it. Normally this is done using a third party that has a mapping of IP addresses to physical locations.
This is of course not 100% accurate, as people may be using VPNs, TOR or simply spoofing addresses.
It's not possible in all cases, but most IP addresses can be mapped to a location (even down to the city). There are quite a large number of such geomapping services.
Use MaxMind service.
http://www.maxmind.com/app/javascript_city
They got free and paid versions.
You can determine the country of the IP address of last proxy that a user is using. This is often their country, but not always.
Users can set out to obscure it e.g. by using TOR or another proxy service.
Or their ISPs might be passing them through NAT or through other countries.
And what do you do with the information? Offer them the site in their presumed-native language? Or customise your contact details appropriately?
So you have to think carefully about how you use this information. It is a good idea to present a page in the native language that you think the user is surfing from, but you must make it easy and obvious for the user to change their country. Not all surfers in any given country actually speak the language, and not all people can call toll-free numbers, and not all people in one country are wanting support that's specific to their country, they may be seeking support for when they are elsewhere or for a friend etc.
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.