MapKit: Check if a user is at an address. (In a Building) - swift

Is there anyway, using MapKit, to check if a user is in a building, at a certain address?
I have the users current position (longitude, latitude):
I have a buildings address - for example, 298 Texas St, San Francisco.
Is there anyway I could tell if a user is at that address / in the building?
I have tried converting coordinates into an address, and just checking the address against the other one, however, my problem is that if the address is a house, and the user walks past it, it will return true, when, in reality, it is not.
Thanks for the help!

Addresses are usually reported as "geo-points", which is just a single lat/long coordinate. Without more information, you know nothing about the size or shape of the dwelling that represents the address.
Also, addresses are sometimes entered into mapping databases by interpolating between a starting address/coordinate and and ending address/coordinate. If the houses aren't evenly spaced, the coordinates of a given address can be wrong.
Plus, GPS's are pretty unreliable indoors, especially in office buildings and multi unit dwellings.
As a result, the short answer to your question is no.
You could ask the location manager for lat/long coordinates of the address, and then use another location manager call to get the distance from the user's current location, and use a distance value (20 meters?) to decide that the user is "at that address". That's likely the best you're going to be able to do.

Related

Finding the next intersection on the current street by using OpenStreetMap

I'm new to OSM and would like to know if my approach for finding the next intersection ahead is possible when doing it offline.
The goal is to get the coordinates (latitude/longitude) of the next intersection on the street I'm currently driving on. For that I have my actual position (lat/lon coordinates) and heading (w.r.t. the north-pole) at disposition.
My current approach right now is to first use my coordinates for getting the name of the street/way/trace in which I am driving; then use that name for knowing which are the next intersections on that street (to both sides); and then use the heading for knowing which direction is the one I should pay attention to.
Once I have the intersection, I would get its coordinates and continue with the program.
My questions are then, is it possible to do all of that offline, i.e. with a .osm file (or similar)?
And, do you know a better approach for getting the coordinates of the next intersection ahead?
Thanks a lot in advance!
PS. I was able to get the name of the street by using nominatim and to get all the intersections of a street by using Overpass turbo, but this solutions would need internet; or is there a way of using them offline?

Converting an address to geolocation and adding a range

I have city address and state on my server.
I need to fetch data in my iPhone application as per distance range (i.e in miles).
Please give some proper suggestions.
You can use Google Geocoding to get Lat-Long form address.
For example :
http://maps.google.com/maps/api/geocode/json?sensor=false&address=newyork,us
address — The address that you want to geocode.
You can use the google geolocation service, where it will get the Lat long from the address or vice-a-versa.
Please read the FAQ for the same.
Another is Foursquare which also nice to use and provides good data.
This will solve your issue.
You can travel to each of your cities and measure the highest position of some stars.
Through the altitude relation you can calculate then you current latitude.
The longitude is a bit more complicated. You need an accurate clock and a table/chart of star positions/times. Then you take measure the time of the highest position of some stars and compare it to your table. with the difference of this two values you can calculate the longitude of the city.
But there are already people who did that and share their results.

Getting cross streets from a geocoded address

Let's say I have a lot of JSON data relating to intersections and their geolocations.
I have an app where the user uses his or her current location, and I want to be able to figure out what block they're on (i.e. the street they're on, and between what two cross streets). What's the best way to do this? Is there a good way?
Example: I get the user's geolocation, reverse-geocode it into 435 W. 42nd st. Using that data, I want to know that the user is between 9th ave and 10th ave on 42nd st.
Any help is much appreciated!
You'll need to have the geolocations of each of the intersections, blocks or whatever you want to relate the user position to. Once you have that information, you can easily find the nearest intersections to the user's current geolocation.
If all of the geolocation information is in your JSON data, then work only in geolocations (don't reverse geocode) until you've determine the nearest intersections, etc.
You'll likely do best to convert your JSON data to a database so you can query more easily.

Finding users close to you while the coordinates of you and others is free to change

I have a database with the current coordinates of every online user. With a push of a button the user can update his/her coordinates to update his current location (which are then sent off to server). The app will allow you to set the radius of a circle (where the user is in the center) in which you can see the other users on a map. The users outside the circle are discarded.
What is the optimal way to find the users around you?
1) The easiest solution is to find the distance between you and every user and then see if it's less than the radius. This would place the sever under unnecessarily great load as comparison has to be made with every user in the world. In addition, how would one deal with changes in the locations?
2) An improved way would be to only calculate and compare the distance with other users who have similar latitude and longitude. Again in order to be efficient, if the radius is decreased the app should only target users with even closer coordinates. This is not as easy as it sounds. If one were to walk around the North Pole with, say, 10m radius then every step around the circumference would equal to a change of 9 degrees longitude. Every step along the equator would be marginal. Still, even being very rough and assuming there aren't many users visiting the Poles I could narrow it down to some extent.
Any ideas regarding finding users close-by and how to keep them up to date would be much appreciated! :)
Andres
Very good practice is to use GeoHash concept (http://geohash.org/) or GeoModel http://code.google.com/p/geomodel/ (better for BigTable like databases). Those are efficient ways of geospatial searches. I encourage you to read some of those at links I have provided, but in few words:
GeoHash translates lon and lat to unique hash string, than you can query database through those hashes. If points are closer to each other similar prefix will bi longer
GeoModel is similar to GegoHash with that difference that hashed are squares with set accuracy. If square is smaller the hash is longer.
Hope I have helped you. But decision, which you will pick, is yours :).
Lukasz
1) you would probably need a two step process here.
a) Assuming that all locations go into a database, you can do a compare at the sql level (very rough one) based on the lat & long, i.e. if you're looking for 100m distances you can safely disregard locations that differ by more than 0.01 degree in both directions. I don't think your North Pole users will mind ;)
Also, don't consider this unnecessary - better do it on the server than the iPhone.
b) you can then use, for the remaining entries, a comparison formula as outlined below.
2) you can find a way to calculate distances between two coordinates here http://snipplr.com/view/2531/calculate-the-distance-between-two-coordinates-latitude-longitude/
The best solution currently, in my opinion, is to wrap the whole earth in a matrix. Every cell will cover a small area and have a unique identifier. This information would be stored for every coordinate in the database and it allows me to quickly filter out irrelevant users (who are very far away). Then use Pythagoras to calculate the distance between all the other users and the client.

Translate GPS coordinates to location on PDF Map

I'd like to know (from a high level view) what would be required to take a pdf floor plan of a building and determine where exactly you are on that floor plan using GPS coordinates? In addition to location, the user would be presented with a "turn by turn" directions to another point on the map, navigating down hallways, between cubicles, etc.
Use case: an iPhone app that determined a user's location and guided them to a conference room or person's office in the building.
I realize that this is by no means trivial, but any help is appreciated. Thanks!
It's an interesting problem. When you're using Core Location, you're not necessarily using GPS. Using WiFi and cell tower triangulation, you can get pretty good location results. So from Core Location you get a latitude and longitude fix. (You might also get altitude info, since GPS data is 3-dimensional. You also will get an accuracy value.)
So you have lat and lon. You need to map these coordinates to the PDF plan's coordinates. Assuming that the plan is aligned with the latitude and longitude lines, and that you have a lat-long fix for one of the points on the plan, you need to calculate the x-axis scale and y-axis scale. Then it's some calculations to map the lat-long to x-y coordinates on the PDF plan.
GPS may not be accurate enough for this purpose, especially indoors. Assuming errors on
the order of 10 meters, you'll have difficulty determining which floor the user is on.
Here's a neat (?) idea that might work: can you post some "You are here" placards
at various locations around the building? You could label each one with a unique,
machine-readable location code (maybe a QR code or something similar), then take an
image using the camera, have your app read that image and interpret the location code,
and use that instead of GPS to determine the start location.
GPS inside? That's your first -- and biggest -- hurdle.
Next hurdle is knowing the GPS coordinates of at least three points on that PDF to define the plane of of your map in the real world. (The PDF will need to be to scale, of course.)
So that gives you where you are on the PDF. Now you'll need to figure out some way to determine where you can walk (or where you can't) to get directions.