Separate geopoint into lat and long - ios

I have GeoPoint's in Parse that I need to separate into the latitude and longitude so that I can define a point. I was having issues so then I created two sting fields in Parse one just with the latitude and the other with just the longitude but now it will not work because it is not a number. I am new to Xcode and could use any help. Here is my current code:
CLLocation *location = [[CLLocation alloc] initWithLatitude:EventLat.text
longitude:EventLong.text];
Any help would be greatly appreciated.

PFGeoPoint has latitude and longitude properties. They are both doubles. Just use... theGeoPoint.latitude etc... Also, your current code will not work because you are trying to put strings into something that is expecting doubles.
You can read the docs on PFGeoint here... https://parse.com/docs/ios/api/Classes/PFGeoPoint.html

Related

How we can get distance between two places's coordinate in ios

I am making an app based on google map.where I am measuring distance between two places. so I have tried to find distance between two place coordinate by predefined method "getDistanceFrom" and tried with googleDirectionAPi.
if I use predefine method I did not get correct distance.
if I use googleDirectionApi sometimes I did not get response.
so please suggest me solution where I can find response on every hit of api and will able to get distance between two place?
You can very easily get the distance between two locations using CoreLocation.
The documentation for CLLocation shows this... https://developer.apple.com/documentation/corelocation/cllocation#
You can create a CLLocation like...
CLLocation* location1 = [[CLLocation alloc] initWithLatitude:lat1 longitude:long1]
Once you have two locations you can find the distance with...
CLLocationDistance distance = [location1 distanceFromLocation: location2];
Note, the documentation shows that getDistanceFrom was deprecated in iOS3.2 (about 8 years ago) so don't use that.
(Forgive any errors in syntax, it has been a few years since I wrote any Objective-C) :D
You need to use these coordinates to get the CLLocations for the respective coordinates using the following line of code
CLLocation *location1 = [[CLLocation alloc] initWithLatitude:lat1 longitude:long1];
CLLocation *location2 = [[CLLocation alloc] initWithLatitude:lat2 longitude:long2];
NSLog(#"Distance i meters: %f", [location1 distanceFromLocation:location2]);
You need to make a HTTP request, call the folowing URL, and it will return the distance between two points.
https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=Washington,DC&destinations=New+York+City,NY&key=YOUR_API_KEY
To get the API Key go to the google developer console.

How can I convert the data from Polygon to lat, lng

image below is the data that I have and I do not know what is the type of coordinates! I thought it was UTM but it is not!
Can you please help me to understand the type and the way of converting it to the lat and lng?!

Regarding iOS CLLocation API CLLocationCoordinate2DIsValid, how does OS treat GPS valid or not?

Regarding iOS CLLocation API CLLocationCoordinate2DIsValid, how does OS treat CLLocationCoordinate2D (lat and lon) valid or not? As you know lat and lon in CLLocationCoordinate2D are all double data type, double means more precious, such as 3.24579999999, it will always be treated as invalid by CLLocationCoordinate2DIsValid. This kind of problem will always occur in server protocol definition, which needs to change from NSString to double value。Anyone who experienced the same issue please discuss together and thanks in advance.
BOOL CLLocationCoordinate2DIsValid(CLLocationCoordinate2D coord)
You are intermixing 2 things:
CLLocationCoordinate2DIsValid describes whether the values (lat/lon) are in valid range.
The LocationManager will mark an invalid location in the field horizontalAccuracyof CLLLocation, by a negative value. This CLLocation is delivered e.g in locationManager:didUpdateLocations. Such an invalid marked coordinate means there was not a sufficient (GPS) position (navigation solution). Although the lat/lon values of that invalid CLLocation could still could be in valid range (see CLLocationCoordinate2DIsValid)
Further to topic 2, iOS does not state when it marks a location as invalid, but most probably it will directly use the fix-valid flag of the GPS Protocoll. (chip to iOS intern)

How to check if a user is at a specified latitude/longitude in iOS?

I'm wondering if there is a way to check if a user is actually at a specific location or not (or maybe within 50-100 feet of it). I have a CLLocationCoordinate2D defined and I know I can check my mapView.userLocation.coordinate.latitude and mapView.userLocation.coordinate.longitude, but I'm not sure what the best way to check this would be.
Basically you just have to compare the lat lon and calculate the distance. Luckily, iOS has a built-in method for that inside the CLLocation class.
Here is a simple way to do it.
CLLocation* location = [[CLLocation alloc] initWithLatitude:marker.coordinate.latitude longitude:marker.coordinate.longitude];
CLLocationDistance distance = [location distanceFromLocation:userLocation];
the returned value is in meters which you can then easily convert to feet or any other unit of measurement that you are interested in.
Here is the documentation for reference

Parsing NSArray for CLLocation Information

My iOS app uses the information provided by Apple, here, to get various location information about my user. cllocationmanager provides a method for getting location information about the user every-time it changes based on certain parameters:
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
This method is absolutely amazing, and returns all of the data I need, however it returns it as a single value in an NSArray:
<+37.33069626,-122.02967106> +/- 10.00m (speed 3.62 mps / course 82.41) # 2/3/13, 4:42:58 PM Eastern Standard Time
This has all the information I need (by the way, what does the course variable stand for), but I can't figure out how to get it into a more usable form. By usable form, I mean simply the coordinates, time, speed, etc. all in separate NSString / NSDictionary / NSArray values. How can I split the single NSArray value (shown above) into different parts?
I've tried splitting the single NSArray value here using nspredicate, but I could only get the NSPredicate to return a boolean value.
I've tried splitting it with the componentsJoinedByString method, however that can only split the array value with one string and there's no single string that every value can be consistently split by.
Any suggestions on how I can split up the pieces of data given to my iOS app through CLLocationManager? Are there methods or functions which could retrieve / split the same data in a more usable form.
Edit
It seems there was a misunderstanding both on my part and others. I had thought that the CLLocation object was an NSArray object with one value. However, as I learned in the comments (thank you #holex) it is not.
According to this part of the doc, the array contains CLLocations objects. So, just retrieve and process them.
for (CLLocation *location in locations) {
NSLog(#"Latitude: %f, Longitude: %f", location.coordinate.latitude, location.coordinate.longitude);
}

Resources