I have the following:
for location in self.locationsWithinMapFiltered {
self.mapView.addAnnotation(location)
}
but based upon filtering, the user can remove some annotation which do not fulfill their criteria. I have a list of the location_id's to
remove but there doesn't seem to be a way to get out the location_id from the annotation.
I was thinking of using the coordinate's to determine
which is which but that seems like a cumbersome way or just removing all and adding only the ones of interest but again pretty cumbersome. Is there a way to efficiently remove a subset of annotations?
I'm a new programmer. I know how to get the latitude/longitude and how to save items in core data, but I'm not sure how to save latitude and longitude.
https://www.youtube.com/watch?v=GeM7Zw12wbM
I've been watching this tutorial because I want a similar app, but I want to save latitude and longitude too. Any ideas how to do this?
CoreData supports a wide range of number size values. Apple's preferred data type to store latitude and longitudinal values is a CLLocationDegrees object, which has a typealias of Double. So you would store your latitude and longitude values as Double's inside CoreData.
In terms of how your CoreData NSManagedObjectModel should be set up, it would make the most sense to save the coordinates by location. In this case you would have two entities: a location entity with a name property that stores the location as a string, and a coordinate entity with both a latitude and longitude property that stores their corresponding values as a Double. You would need to create a "one to many" relationship linking your location to your coordinates.
Then to retrieve your coordinates you would send a fetch request to your location entity and then simply retrieve each location of type NSManagedObject's corresponding coordinates.
You said you were a new programmer, so know that CoreData is not something to be taken lightly. I recommend you read through Apple's programming guide for Core Data as it explains how to set up your CoreData stack, NSManagedObjectModel, and how to create relationships between two entities; Which I am thinking you will most likely need to relate your location to your coordinates. Good Luck.
Core Data Programming Guide
I hope this isn't an inappropriate post, but I wanted to make sure my first steps implementing parse as my backend are in the right direction to save some time. I'm new to both iOS programming and the parse sdk, so please bear with me!
In my app, users are able to create various polygon shape overlays on a Google Maps mapView, stored as a GMSMutablePath, which is basically a list of coordinates. Users will have at least one group of paths, each with at least one path. There will also be some information stored with each group, stored as strings or numbers. This information is specific to a single group of paths.
I'm trying to figure out the best way to store this data. My first basic question is 1) Can I store the GMSMutablePath as a whole in the Object data type? Or does the Object data type refer to a class that is created through parse? This link (https://www.parse.com/questions/what-is-data-type-of-object-in-data-browser) is the 'best' explanation I found of the Object data type, and it isn't very clear to me.
My gut instinct is no, I can't store the GMSMutablePath object, and that Object refers to a Parse object. Which leads me to 2) How should I store this data, then? I can get the individual lat/long values of the coordinates that make up each path, and I can store those as numbers, and use the numbers to recreate the paths elsewhere. None of the paths should use too many coordinates, and there shouldn't be too many paths in each group.
Playing around a little bit in the data browser, I see that I can store arrays, but I'm not sure how those are formatted, as I'd need an array (of groups) of arrays (of paths) of arrays (of lat/long values). A little bit of googling tells me it can be done, but doesn't show me how. Can any datatype be stored in any array, or is a datatype specified? I'm used to C++ programming, so I'm used to an array containing a single type of element. What I'm thinking is that I'd need an array of objects, which would be the groups of paths. Each one of those objects would have the string/number information associated with the group, as well as an array for the paths within the group. For each one of those paths, it would have to be either an array or an object. Since for the path I just need the coordinate lat/long values, I think that I can get away with an each path being an array of numbers, and I can write my program to use one array, with odd indexes being lat / even indexes being long values. That all being said, I'm not sure how to create all of that. I'm not looking for somebody to write my implementation for me, but all of the examples I can find are much more simple... if anybody could point me in the right direction to do this, or has a better idea of how to do it, I'd love some pointers.
Each user is going to have their own groups, but that data is going to be shared with others at some point. The data will be associated with the user it belongs to. With that in mind, my last question is 3) Should I store all of this information specific to a user and their groups on the User class, or make it all a separate class entirely? My guess it that I should add an Object to the User class, and store the groups within that Object. I just want to make sure I have that right, with future scalability in mind. Like, when I pull the group data, am I going to have to pull the entire User data from another user, and if so, is that going to slow things down significantly? I'm thinking that I do have to send entire user data, but I don't know if that poses any security risks. Would it be best to have a separate class for the groups, and store the user id associated with the groups? If I do this, should I also store the groups as an object on the User class?
Sorry for the wall of text, but thank you for any guidance you can provide!
If you need any clarification, let me know.
Thanks,
Jake
Creating a class to hold all the objects turned out to be unnecessary. It only had a few extra details that were just as convenient to add to the user object, and then have an array of objects on the user.
Some main things to note that I learned are: use addObject to add to an array, rather than setObject to add a single object to a PFObject/User.
Parse fetching/saving happens in background threads, so if you're loading the data to do something specific with it, make sure the code using the data occurs inside a block using the [PFObject fetchInBackgroundWithBlock] method.
Also, as changes are made to the structure of your data on a parse user/object, make sure you sign out of the current user and create a new one on your app, or you may run into lots of undefined behaviour that could crash your app.
For my iOS application, I need to organize a list of Parse objects by their distance from the user's current location. Each of the Parse objects has an attribute for location, but the location is a regular address in the form of an NSString, rather than GPS coordinates or a CLLocation.
I have two questions for this situation:
How do I find the distance between an NSString location and the user's current location?
How do I query for the distance in Parse (for example, only display the objects within 5 miles)?
Thanks for any help!
To perform distance queries, you need a GeoPoint. There are many ways to look up a GeoPoint given a string address.
You could create an Cloud Code after-save method that uses Google to lookup the GeoPoint and add it to the record. Looking up the GeoPoint from a string is an expensive operation, you only want to do this once for each data point when the data changes.
To attempt to find distance based on a string address within a query (would require every record to be evaluated every time) would unfairly tax the geo-lookup facility and probably be a breach of the terms of use.
Once you have an actual GeoPoint in your data then the query is quite easy, as per the documentation:
To limit the results using distance check out whereKey:nearGeoPoint:withinMiles, whereKey:nearGeoPoint:withinKilometers, and whereKey:nearGeoPoint:withinRadians.
I have a list of core data objects each has a longitude and latitude properties.
I have the user location from core location.
I wish to retrieve the nearest object to the user location?
How can I do that?
I'm not going to give you an answer with code as you are only asking a general question.
But, there is a useful function in CLLocation called distanceFromLocation: which has the signature:
- (CLLocationDistance)distanceFromLocation:(const CLLocation *)location
The way to do this would be to store (or create) create CLLocation objects from the locations in your Core Data store, and using the users current location you can iterate through the list of locations using this function to get the distances and then return the location with the smallest return value as the nearest location.