Array of addresses: closest place with iphone geolocation in ios6 - ios6

I have an array of street addresses, I want my app to sort that array starting with the closest address to my location (GPS).
Now that Apple has released iOS Maps in iOS 6, what is the easier way to do that?
Thanks,
Matt.

Approach I'd take would be use CLGeocoder to obtain CLLocation instances for each address (there are several async methods provided by the class to do this). Save the values obtained if needed for future sorts to save having to re-obtain them. Get your location as a CLLocation instance. Use -[ CLLocation distanceFromLocation: ] to obtain distance between your device location and each address location. Sort on these distance values.
Hope this helps!
Mark

Related

How to convert array to unsafe pointer

I am creating an app that tracks a drive, so as you drive it records location and at the end, it shows a map of where you have been. I am using swiftUI's MapKit to display map data. In the process of displaying the information, I ran into a problem.
I plan to use MapKit polyline (MKPolyline) to show the location points but to initialize an MKPolyline, you must first have an unsafe pointer of either MKMapPoints or CLLocationCoordinate2Ds.
init(points: UnsafePointer<MKMapPoint>, count: Int)
init(coordinates: UnsafePointer<CLLocationCoordinate2D>, count: Int)
I have an array of coordinates but need an unsafe pointer instead. How do I go about converting them?
Thanks to Leo and Rob. They told me how. I just put the array right into the coordinates and swift handled the rest for me.
let Line = MKPolyline(coordinates: Locations, count: Locations.count)
Check out this thread for a more in depth answer

Google Maps API - Getting fastest route with multiple way points

I have been reviewing the Google maps API, (specifically the Directions API), and in theory I know what I want but am having trouble finding the documentation for it;
I have a set of addresses that I would like the fastest route for;
maps.googleapis.com/maps/api/directions/json?origin=START_ADDRESS&destination=###1###&waypoints=###2###,###3###,###ETC###&key=MY_API_KEY
I have surrounded the params I will explain below with ###;
1; This is unknown as I want the furthest address to be the last point; At the moment this is done by getting all of the times distance and just doing it that way, but If I have 3 addresses and address 2 is closer than address 3, but its quicker to go to address 1 then address 3 then address 2 last then it's not good.
2&3; Google seems to just go through the addresses in the order I put them here, and what I actually want is to go in order of the fastest route, the order of addresses does not actually indicate this.
Just wondering what approach I could take, is there something I have missed in the API,
Thanks in advance,
Robert
NB: If something isn't clear please comment and I will try to clarify.
Found out there is an optimise parameter for way-points!:
maps.googleapis.com/maps/api/directions/json?origin=x&destination=x&waypoints=optimise:true|y|z&key=MY_API_KEY

Calculating length of a street with Google Maps

I have to calculate length of a street with Google Maps API. I've already searched for "start and end point of a street", etc... there are no good solutions.
What I need in example:
1. Look for "Ludwigstraße, München"
2. Get length of this street in meter (miles or whatever)
Does anyone have a good idea or any other method how to manage this? Perhaps there is a possibility to make this via overlays?
If you had start and end point of street already, try to use google map api distance matrix, that service will return the distance between start and end point.enter link description here

Open iOS 6 native map from URL passing address string # given coordinates

Prior to iOS 6 you could open the map app passing a destination address using this URL:
http://maps.google.com/maps/?daddr=Tom's%20House#40.70,-74.10
Note the address format: mystring#latitude,longitude
Where you basically tell the app to place the marker at the given coordinates and show "mystring" in the address field.
With iOS 6 they changed the host from maps.google.com to maps.apple.com, but now the above address format does not work anymore:
http://maps.apple.com/maps/?daddr=Tom's%20House#40.70,-74.10
As daddr you can pass EITHER a real address OR just the coordinates but, apparently, not both.
The Apple docs about this: Apple URL Scheme Reference are not very helpful as they contain no mention of how saddr and daddr fields can be formatted.
Does anybody know if this format/behavior is still supported somehow?

Plotting Address on Virtual Earth

How can I plot a point of an address on a map?
I want to basically use VEMap.Find(), but simply get the coordinates of the location.
When you call Find(), pass in true for the showResults parameter. The Microsoft doc has an example of how to do this: Microsoft's VEMap.Find() documentation
If you really only want the lat/long of a result returned from VEMap.Find(), check out this blog post: Getting Coordinates from VEMap.Find(). The coordinates are accessible in the GetCoordinates function as properties of the findPlaceResults object.

Resources