Hey are coordinates from Apple Maps incorrect when used as a CLLocation in mapkit? - swift

I’m working on an app that shows various places on a map (SwiftUI using mkmapkit in a uiViewRepresentable) and have found that coordinates are being placed off target for some reason.
I have the data listed in Firebase as a map - Latitude value and Longitude value that is then transferred into a CLLocation in app.
Example of the problem is that Big Ben in London should be (according to Apple Maps) be at 51.50070N and 0.12455W doesn’t appear there in app (see image) but the app reports coordinates of 51.500702, 0.124610 - when tapped just below the annotation.reported coordinates

The sign on the longitude is incorrect. According to my MKLocalSearch (and confirmed by dropping an annotation there), Big Ben is at a latitude of 51.5006854 and a longitude of -0.1245698. Note, that's -0.1245698 (aka, 0.1245698W) and not 0.1245698 (aka 0.1245698E).
A longitude is defined “relative to the zero meridian, with positive values extending east of the meridian and negative values extending west of the meridian.”
But your map is showing the coordinate east of the meridian, not the one west of the meridian. Here are the two coordinates:
And zooming in on that incorrect coordinate to the east, that's obviously where your map is pointing:
But Big Ben is to the west of the meridian:

Related

plot pins on MKMapView around 10 kms from current location

I have an MKMapView & I am using PinAnnotation for plotting the pins on MKMapView.
I have a local database which contains the latitude & longitude of thousands of locations. I want to plot the pins around 10 kms from current location on MKMapView, when the application is launched.
It depends what your database. A simplistic way would be to work out the longitude difference for 10km (it is different at the equator and near the north pole) and the latitude difference for 10km, then search your database for everything between maxLat and minLat and maxLong and minLong. That gives you items in a rectangle but it's a start. From there you could cycle through every result, make it a CLLocation and check it is within 10km using distanceFromLocation.
I done it using the following way -
1) First found the current latitude & longitude using the delegate method of MKMapView(didUpdateUserLocation).
2) Found the distance from the current location with the location stored in my local DB in KM.
3) If distance <=10 Kms, then plot pin, else do nothing.

iOS is it possible to convert CLLocation into some sort of XYZ metric coordinate system?

I'm building an augmented reality game, and working with CLLocation is rather cumbersome.
Is there some way to locally approximate CLLocation as XYZ coordinate, expressed in meters with the origin starting at some arbitrary point (for example the initial position when the game was started)?
Lets say I'm working with a 1 mile radius and do not really care about the curvature of the earth. Is it possible to approximate or somehow simplify the location based calculations for local position tracking?
Alternatively, is there a coordinate system that can be used with CLLocation that also incorporates the roll, pitch, yaw of the CMAttitude as well as compass orientation?
Clarification: As far as I understand, the problem with latitude and longitude is that their units vary in size, depending on the position on the globe. I should've specified that X,Y,Z should be in standard units, like meters or feet.
Thank you!
The Haversine formula may be useful.
I found a good article on it at http://www.jaimerios.com/?p=39 with code examples.
You could get the initial point at the app's launch and calculate the relative points based on the user coordinates as he or she moves. Admittedly, this is not super elegant, but if you are just trying to do some simple comparisons based on the user's location relative to an arbitrary origin, this should work. For the Z, Alex Stone's suggestion of calculating it based on the altitude should be fine.

Why points above 85N or below -85S are not shown on the iPhone map?

I need to represent on the map (iPhone) some points such as (88, 60) or (90, 55), but the custom annotations representing these points get deallocated. I also noticed that these points are not actually displayed on the google map, they are somehow above the visible map. This happens for any point that is above 85 deg. N latitude or -85 deg. S latitude.
I know it's a really old post, but just to answer your question.
Most (allmost all) commercial maps are displayed in the mercator projection. This is what you see in mapKit or on google maps. This means that the latitude and longitude lines run horizontal and vertical.
If you would change this to for instance polar project (world from the top) it would become way to difficult to calculate the postion of objects because the lat and long lines converge rapidly...
So it's just for ease of use....

Longitude, Latitude to XY coordinate conversion

I want to now how to convert longitude, latitude to its equivalent xy coordinate components in iPhone programming. (I am using only CoreLocation programming, and want to show a point on iPhone screen without any map).
thanks
Well the exact conversion depends on exactly which part of the Earth you want to show, and the stretching along longitude varies according to latitude, at least in Mercator.
That being said, even if you don't want to display an actual MapKit map, it would probably be easiest to create an MKMapView and keep it to one side. If you set the area you want to display appropriately on that (by setting the region property), you can use convertCoordinate:toPointToView: to map from longitude and latitude to a 2d screen location.
Note that MKMapView adjusts the region you set so as to make sense for the viewport its been given (eg, if you gave it a region that was a short fat rectangle, but the view it had was a tall thin rectangle, it'd pick the smallest region that covers the entire short fat rectangle but is the shape of a tall thin rectangle), so don't get confused if you specify a region with the top left being a particular geolocation, but then that geolocation isn't at the exact top left of the view.

Why does a pin placed at the same latitude and longitude in MKMapView differ from one in Google Maps?

I drop a pin in an MKMapView with longitude and latitude. When I place same longitude and latitude on google map the pin on both are slightly different.
I have a web/iPhone app that renders a map for positions sourced from the same database and haven't seen this issue. I would check your assumptions:
Are you truncating your values over the wire?
Are you rounding the position values differently on the two platforms?
Check the values you are passing into Google Maps and MapKit by logging them and comparing.
You can see from the following screenshots that the same latitude/longitude are rendered on the same position on the map:
Update
I tried the coordinates you mentioned in the comments and got the same position for both. You need to check your assumptions. The values that you are using on the web or on the device are not the values you think they are: