Core plot : Updating labels using shouldUpdateAxisLabels and shouldUpdateMinorAxisLabels - ios

This is a follow up question to.
Core plot-Add OutOfRange to draw graph that changes dynamically with label "OL".
I am using Automatic labelling policy and using shouldUpdateAxisLabels and shouldUpdateMinorAxisLabels and trying to set the OL label for whichever location is the highest.
In that method,
//Check whether need to set labelling for minTickLocations or majorTickLocations
double maxMajorTickLocationValue = [[[axis.majorTickLocations allObjects] valueForKeyPath:#"#max.doubleValue"] doubleValue];
double minMajorTickLocationValue = [[[axis.majorTickLocations allObjects] valueForKeyPath:#"#min.doubleValue"] doubleValue];
double maxMinorTickLocationValue = [[[axis.minorTickLocations allObjects] valueForKeyPath:#"#max.doubleValue"] doubleValue];
double minMinorTickLocationValue = [[[axis.minorTickLocations allObjects] valueForKeyPath:#"#min.doubleValue"] doubleValue];
while setting labels, I check if location is highest location, for e.g., if location is in majorLocations array and if its greater than maxMinorLocation and set "OL". Similarly for min value with "-OL".
Issue I am facing here is, labelling will always happen on minor locations. So for eg., in case of UI if highest location is a major location and lowest is a minor location, setting of OL label to a major location and -OL to a minor location does not work and labels will be set to only minor locations. Attaching graph image as well.
So pls suggest.
/Users/shrikanth/Desktop/Screen Shot 2017-01-02 at 7.23.06 AM.png

Related

How To Detect A User Is Within Range Of An Annotation

So I am working on a project that includes many uses placing annotations all around a map. The annotation, (which is a custom image with a much larger circular range) appears on the screen and, ideally, I would like for a user to be:
Notified if they are within the range of a annotation
and
Not be allowed to place another annotation within the range of another one if the circular pins overlap by, say, more than 25%
I think this is a pretty unique question and should be fun for somebody to help out with, so have fun! Thanks everybody!
You can check the distance from each annotation using
- (CLLocationDistance)distanceFromLocation:(const CLLocation *)location
This method measures the distance between the two locations by tracing
a line between them that follows the curvature of the Earth. The
resulting arc is a smooth curve and does not take into account
specific altitude changes between the two locations.
For more details refer Link
Try this:
let location = CLLocation(latitude: 1, longitude: 1)//Or user's location
let distance = location.distance(from: anotherLocation)
Edit:
As mentioned in the comments, you wanted to create an equidistant point. I suggest manually doing that:
Subtract the annotation's location from he user's location. Then add your distance back to the original one. For example:
The user's location = (1, 1)
The annotation's location = (3, 2)
Vertical difference would be 2
Horizontal difference would be 1
Then:
(3 + 2, 2 + 1)
Your result: (5, 3)
Now you would have two points (the one you just created and the user's location) at each end with a center point (original annotation)

Delivery radius for a restaurant in Apple Maps

I'm trying to develop a delivery system for a restaurant, but I'm not sure how to approach this problem. The restaurant has five locations; four of them are in one state and the other is in a different state.
They only do deliveries for each location depending on how far it is; they also have setup certain limitations for each location.
My idea will be:
Fetch user's location on iOS (Accomplished)
Check if user location is inside of any Restaurant delivery radius. If so, set that location as the store, if not, just show a message that we don't delivery in their area.
Where I'm stuck
How can I define in Apple Maps the limits of Location 1, 2, 3, etc. (meaning what area will they be doing delivery to)?
Try setting the deliverable radius around the location of the restaurant. You can even draw an MKCircle to be fancy.
CLLocation * _storeLocation = [[CLLocation alloc] initWithLatitude:30.270135 longitude:-97.731270];
double deliverableRadius = 3 * 1609.34; // 3 miles (or the area they will deliver to)
MKCircle * circle = [MKCircle circleWithCenterCoordinate:storeLocation.coordinate radius:deliverableRadius];
[_mapView addOverlay:circle];
Once you have established the deliverable area, you can check to see if the see if the users location is within this area.
So I think a simple approach might be to simply check if the user is within a certain distance of a restaurant (ie "If I am less than 25 miles from a restaurant, then they will deliver to me").
First convert the address of the restaurant locations into gps coordinates. See Converting Place Names Into Coordinates for more info.
Next, calculate the distance between the user's location and the location of each restaurant and check if that distance less than the maximum delivery distance.
A formula for calcualating the distance between two points can be found here.

Find places within the boundaries of given locations

in my maps app i have to find the places (bank,ATM,cafe,bar..) inside bound of selected locations.Actually i have to get the places which are centre to the given locations.
for example i have 4 places a,b,c,d i have to get all banks inside bounds of these 4 places and have show them on map.
i can get nearest places for each location individually by using GooglePlaces API.but i need show places which are centre(approximately) to these 4 places.
please give me any suggestions how to do this or any example code or any other tutorials or links....
Thanks
Raki.
Your solution would be to take the average lat/lon of your points and then hit your Google API to get locations in that area. This average will be in the middle of however many coordinates you have. Example:
double totalLat = 0;
double totalLon = 0;
for(CLLocationCoordinate2D coordinate in coordinateArray)
{
totalLat += coordinate.latitude;
totalLon += coordinate.longitude;
}
// Use this average coordinate (which is the center of your points) to hit your Google API
CLLocationCoordinate2D averageCoordinate = CLLocationCoordinate2DMake(totalLat / coordinateArray.count, totalLon / coordinateArray.count);
Note: I haven't actually tested this, so don't just copy/paste, but it's the general idea.
You can always use the radius parameter defined in the Places API to get this information.
Please follow this Stack Overflow answer for more details.

Sort the nearest locations using coordinates?

I have list a of places with coordinates
If users select particular location I want to suggest list of locations nearby using coordinates
I can achieve that by putting loop and searching all the places within the distance from the following code
for(i=0;i<locations.count;i++)
CLLocation *locA = [[CLLocation alloc] initWithLatitude:lat1 longitude:long1];
CLLocation *locB = [[CLLocation alloc] initWithLatitude:lat2 longitude:long2];
CLLocationDistance distance = [locA distanceFromLocation:locB];
// if(distance<10)
//{
//show the pin
// }
But I guess It not a efficient way if we have more locations in the database
What I can I do here
Is there any alternative way??
You should filter the content to reduce the amount you extract from the database. You need to define what 'nearby' means in your case, calculate the lat/long bounding box where everything outside that box is not 'nearby' and use the box min and max lat/long values to exclude things that don't match. This is done as part of the SQL query so it's very efficient.
Now, your question loop logic comes into play. The approach is fine, though using your own loop likely isn't best. Instead, look at using sortedArrayUsingComparator: or sortedArrayUsingFunction:context:.

iOS Compare GPS locations

I'm creating an application which needs to determine if my current location (recd in didUpdateLocation:) is present among a set of geo-coordinates I have. Now I understand that comparing double/float values for equality can be error prone as the precisions involved in geo-coordinates is very high. Slight inaccuracy in the GPS can throw my algo off-track. Hence I need to compare it with some error margin.
How do I compare 2 CLLocations with a margin of error? Or determine the error in the location reading (I don't think this is possible since CLLocationManager would have rectified it).
Thanks in advance :)
In each CLLocation instance there is a property declared as #property(readonly, nonatomic) CLLocationAccuracy horizontalAccuracy; What you can do is to make a routine like:
-(BOOL)isLocation:(CLLocation*)location inRangeWith:(CLLocation*)otherLocation{
CLLocationDistance delta = [location distanceFromLocation:otherLocation];
return (delta < location.horizontalAccuracy);
}
You can make even more complex logic as both locations have that property...
Cheers.
【ツ】
You can use the CoreLocation method distanceFromLocation: to find the distance between the user's location and another point. If the distance is less than whatever threshold you decide, then you can assume the locations are the same.
CLLocationDistance threshold = 5.0; // threshold distance in meters
// note: userLocation and otherLocation are CLLocation objects
if ([userLocation distanceFromLocation:otherLocation] <= threshold) {
// same location
}

Resources