Identifying user's location based not on IP - php

I know how can I determine user's location using IP number. However, I'm wondering if there is some more precise technique. I've seen that some applications, eg. Google MAPS, are asking a user for permission to get his location. Is there some kind of such API? Am I missing something?
Thanks a lot!

The only generally available, more exact method known to me is the HTML 5 geolocation API. That API can sometimes fetch a more exact location by scanning nearby wireless networks and their IDs, or querying a GPS device attached to the computer (or as #Pascal says, a GPS device built into a mobile device like an iPhone).
This however works only if the computer has the right hardware, and requires explicit consent from the user.
For user-consent-free, server-side geolocation, the IP-based method is still the best you can do.
See this question for a great rundown on how it works: About Geolocation in HTML 5

Some devices (typically, smartphones) have a GPS -- which means quite precise location -- or can use wifi / cell-towers / ...
You cannot get that location on the server (it's not sent by the browser), but you could get it from Javascript (and, then, send it to the server, using some Ajax).
For some documentation, you can take a look at :
W3C Geolocation API
And Using geolocation (which applies at least to Firefox >= 3.5)

Seems to be problems with GeoLocation in HTML5 http://ipgeo5.com/
Yesterday I was in Montreal and worked perfectly pinpointing my current location to the nearest 30 feet(estimate). Running Windows XP, Chrome 14.0.835.
Today, I am at my mom's house in a small town in Ontario, Canada and getting this error.
Your Current Location
We have estimated you are located at
Notice: Undefined property: stdClass::$AdministrativeArea in /var/www/ipgeo5.com/pages/city.php on line 29
Notice: Trying to get property of non-object in /var/www/ipgeo5.com/pages/city.php on line 29
, , Canada by using HTML 5 Geolocation technique.
Your location:
Notice: Undefined property: stdClass::$AdministrativeArea in /var/www/ipgeo5.com/pages/city.php on line 29
Notice: Trying to get property of non-object in /var/www/ipgeo5.com/pages/city.php on line 29
, , Canada
So I guess this is not 100% effective !
So needs to have Plan B using IP2Location database to identify location.
Thanks !
Michel, Montreal, Canada

That would be the geolocation API.

See the Geolocation API and the matching section of Dive into HTML 5

Related

Google Maps Geocode Issues: Certain Encoded URLs Failing

I am trying to get Lat/Lon for a list of locations from an address. It works for most addresses, but certain ones fail and return Zero Results.
Take this address as an example: 1045 Mono Way, Sonora, CA 95370
As you can see, that is a valid address on Google Maps - no issues there.
When pinging the Geocoder Api, I am encoding the address using urlencode(). This is the encoded address: 1045%20Mono%20Way%2C%20Sonora%2C%20CA%2095370
This is the link that I am accessing:
https://maps.googleapis.com/maps/api/geocode/xml?address=1045%20Mono%20Way%2C%20Sonora%2C%20CA%2095370&sensor=false
As you can see, zero results.
Now, if you change the first part of the address (1045) to any other number (e.g. 1044), you will get valid results.
I am lost.
Need help.
Please ;)
BTW, I am using this reply to get the lat/lon from the API: Google Maps - converting address to latitude & longitude - PHP backend?
I would bet that address just doesn't exist. The addresses are provided by local government, typically in a range of numbers that corresponds to a stretch of street. The fact that trying odd numbers doesn't work (1045, 1047, 1049) but even numbers do (1044, 1046, 1048) suggests that the addresses on one side of the road are not there. Or at least not in the dataset provided by the city or county.
The ideal solution would be a "fuzziness" argument to the API call, which would return a location similar to what their Maps site is. But since we can't rewrite third party APIs, I'd suggest checking for a "ZERO_RESULTS" response, and then resubmitting the request with just the street name if needed.
Also, you can do a geocode search without your API key, so you may want to keep that out of your question!

Finding geology of a GPS location like in water or on a road

I am working on a project that I have array of GPS locations.
I want to know for each of those points, where are they?
I have a specific list that I am trying to match their location to one of those such as: Water, Highway, railway, ...
I tried this API (http://developers.cloudmade.com/wiki/geocoding-http-api/Documentation) but it doesn't give me any accurate data! even less than 50% correct!
Do you know any better solution?
I use php for server side that is responsible to gathering data from different webservices.
Our client sides are Android, Java
I expect system search and find the type of location automaticall
You don't give any hint of your platform (pc? smartphone? by hand? In automated program?)
But as a great starting point working with a few points by hand, in maps.google.com if you put the latitude and longitude (may be longitude and latitude try both) it will show them to you on the map. Google maps even has simple APIs so you can use this functionality reasonably simply (for example from a matlab program).

IP to location + local time?

Currently I've been using http://www.geoiptool.com/ but I can't get the local time. I don't know what to do to get the local time.
Can someone help me out, to display location + local time? I have a mail app and I try to display IP in location + local time.
Well, this is not real answer to your question but can help you to properly understand how inaccurate this method is.
Please, read this answer as a side note.
Yes, it's OK to offer or set location/time for your users. But you should provide country/time selector for them also. Some of IP's can not be resolved properly (anonymous proxy, borrowed IPs from other countries (my case), continental IPs (like group "Europe", "Asia", etc), etc.
My case shows how this approach may be wrong.
When I've tried ipLocator from geobytes.com I've got this:
My IP address has been resolved to:
Location: Romania
Time offset: +0200 (at the moment DST is active so it's +0300)
Real problem is that my location is not Romania, and my time offset is +0100/+0200.
Look this picture:
Red arrow shows my real location. Info in black box shows correct values for my real location. Well, wrong location is not such a big problem for users, but wrong local time is very annoying thing.
Yes, I know, that's not what you're looking for. But you should not fix users location and/or local time because it can be wrong approach. IPv4 address is certainly not something accurate to get real info about user.
Also, I found that ipLocator doesn't follow DST rules and using that time offset (image #1) will show wrong local time during Summer (for countries/regions/provinces which consider DST).
Geobytes will give you the offset:
http://www.geobytes.com/IpLocator.htm?GetLocation&IpAddress=64.34.119.12
Or in an XML format (you might need to view source to see it):
http://www.geobytes.com/IpLocator.htm?GetLocation&template=php3.txt&IpAddress=64.34.119.12
This will give you the offset, just add/subtract the offset to GMT/UTC.

Mobile Handset detection Using Tera-WURFL

I develop a wap portal for games. My problem is to detect handset device perfectly. My games provider provide me the supported handset list like this:
Nokia6300, SGH-X200, MOT-C261, SIE-CX70, SAMSUNG-SGH-Z140
So, I have to detect the supported games for the particular wap user.
I can easily detect the handset for nokia devices using below command:
require_once('../TeraWurfl.php');
$wurflObj = new TeraWurfl();
$matched = $wurflObj->getDeviceCapabilitiesFromAgent();
$brand_name = $wurflObj->getDeviceCapability("brand_name");
$model_name = $wurflObj->getDeviceCapability("model_name");
$handset=$brand_name. $model_name;
//Nokia6300,Nokia6600 etc.
But the problem is for siemence ,Motorola ,some Samsung sets,and lot of others.
Let say the user agent:
SIE-CX70/36 UP.Browser/7.0.2.2.156(GUI) MMP/2.0 Profile/MIDP-2.0 Configuration/CLDC-1.1
Provide me the model name: CX70 and Brand Name: Siemens.
So if I concatenate then get the value: SiemensCX70.But the actual is: SIE-CX70.
So, Information mis-match.
Now my question is how can I detection the perfect handset.
Please help me to retrieve the actual info.
Thanks
riad
I guess you have already figured this out, there is no easy way to do this, you will need to maintain a mapping on your side that maps the WURFLMODELNAME to the actual handset that your client gives. This way you can have a better Display of the handset names. Make sure you can do a many to one mapping so that you can map 1 or many WURFL Model Names to 1 Handset Display name.
You could utilize UAProf, a URL of RDF format which describes handset capabilities, together with the user agent because UAProf does not always exist in the header. I won't say it's perfect because there is always some exception. I have seen a RDF file which has invalid format. But it might be helpful for your case.
Please refer to this simple example (Restlet):
http://shengchien.blogspot.com/2010/09/restful-mobile-detection.html

UK postcodes -> co-ordinates : possible purely in php?

Say have a mysql database with these cols:
| house | postcode | lat | lon |
The postcode's are complete but lat and lon are empty.
I want to write/find a script that i can run once to complete the table.
Is this possible purely in php (any tips?) or do i need to use a javascript api and $_POST to a php file?
Without needing any external API
UK Postcode data is now freely available from the Ordnance Survey CodePoint as a downloadable series of CSV files (Feb 2009); but unfortunately the location point is stored using Northing/Eastings rather than Latitude and Longitude.
You'd need to convert the Northings/Eastings to Latitude/Longitude. There's a number of articles about this on the web, e.g.
http://www.deepbluesky.com/blog/-/converting-os-coodinates-into-longitude-latitude_7/
http://mediakey.dk/~cc/convert-northing-and-easting-utm-to-longitude-and-latitude/
but you need to be aware that OS Northings/Eastings are based on the Airy 1830 ellipsoid rather than the WGS84 model used by Google maps (and most GSM systems). Failing to allow for this difference can put you out by anything between 70-120m between Cornwall and East Anglia.
Using PHP, the best solution for this conversion is PHPCoord by Jonathan Stott
There's an XML/JSON API PHP can access via HTTP requests like file_get_contents or cURL.
http://code.google.com/apis/maps/documentation/geocoding/
This can be done purely in PHP, relying on some external API that provides you with the lat/lon data.
Generally, web APIs do not care much about the language that's running on their clients. With "JavaScript API" you probably mean a service that returns data in some JavaScript-friendly format, like JSON. However, JSON does not have to be processed by a JavaScript program; PHP programs can parse it just fine.

Categories