I need to identify coordinates for the range selected by User. I can get users current coordinates by coreLocation but I need to pick places of interest in user selected value range say 1 mile within his current location. Essentially I want to circle around 1 mile coordinates.
Any help/lead would really be appreciated, I am new to iPhone programming.
Related
I am making a location based tracking program where user can set his/her origin and destination point and then a polyline will be generated based on two coordinates. Now I want to know if user's current location is near or within polylines.
List<LatLng> coordinates is the coordinates that are used to draw polylines on Map.
Stream<LatLng> currentLocation is the stream that is listening to user's current location.
Never mind 😅
I found out there is a method on native google map PolyUtil isLocationOnPath() which return true if given point is within or near given List of coordinates.
I made a flutter plugin for that google_map_polyutil
First determine the value of "near" and you sould try to add or subtract this value to lat and long of the user and see if the new location has cross the line. (Signe of the addition or subtract has change).
I'm using Core Location with ios 6 for this.
Scenario:
I have the spacial coordinates of a sample of points. I save all those coords using core data.
As and when I am moving with my iphone, I need to detect if I am like 500m from any points in that sample.
Right now, I am looping through those points and calculating the distances of them from my current location. It does this frequently as the user's current location is changing.
But the thing is this will not be a good idea if I have like 100 points, 1000 points.etc
Question:
How can I optimize this, any hint?
Idea:
rasterize (grid) your objects and asign each object to a grid-object (clustering).
while moving, detect the grids intersecting your current position/radius.
get the most nearby object(s) inside those grids.
So you only need to calculate the distances of your grid-objects and the distances to the objects inside the grid-objects nearby your position.
I am developing one iphone application which contains maps. Starting screen is navigation screen where user can select location, lets say florida. Now when User selects florida i want to pick up at least six random points (latitude and longitude of points so that I can put annotation) from florida only.
I do not have DB so that I can not fetch 5 points from DB for florida and place them.
Any ideas?
Thanks,
This is going to be quite hard if you don't have anything to tell you the shape and size of the area you are trying to produce random points within. Harikrishnan had given you a good start, though increasing the lat and long by 0.0001 each time is hardly random. At Florida's coordintes (28.0908° N, 81.9604° W according to Google) moving 0.0001 in both directions is only 14m away, so you're unlikely to leave Florida at that speed.
You could adjust Harikirshnan's method by using a random number instead of 0.0001, but you still need to know how big the area is that your user is looking at. Having 5 points all 14m when you're looking at a state, or even a city, is not much good.
Maybe you need to look more closely at what you are trying to achieve. If the points don't represent geographical data then why are you putting them on a map. If they do and they represent the entire area and not a single point then the best I can think of is to generate random points based on the maprect that Apple returns for the location the user has chosen. (roughly speaking that would be mapX = random*maprect.size.width + maprect.origin.x). And then incase you have an area like Florida that is not perfectly shaped like your MKMapView you'd need to reverse geocode to see if the point you picked really is within Florida (i.e. send the coords to Apple and check the address).
Or, you could consider now showing the data on the map
Try this
NSInteger i;
double offset=0.0001;
for(i=1;i<=5;i++){
double newlatitude=location.coordinate.longitude+offset;
double newlongitude=location.coordinate.longitude+offset;
NSLog(#"%f ,%f",newlatitude,newlongitude );
offset+=0.0001;
}
I want to draw a line on Map as per user's location changes (GPS Base), and i also want to measure distance user?
Regarding the part "i also want to measure distance".
Use "distanceFromLocation:" to measure the distance in meters, between two locations.
http://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocation_Class/CLLocation/CLLocation.html#//apple_ref/doc/uid/TP40007126-CH3-SW18
I have my current location from CLLocation,
and I have another location- also an CLLocation.
I would like to detect when my device is heading towards that other location.
(I can calculate the distance in meters between this points- but can't workout
the calculation of an accurate angle to compare with the device current heading)
Thanks.
How about using CLLocation's built-in course property?
To Be deleted
One approach could be to continuously calculate the distance between current location and target location. if the distance decreases, your device is moving towards the the target.
In a real world szenario (car in city, car in mountainous country e.g. Switzerland) this doesn't work. You would need some array of way-points (e.g. intersections) that lead towards the target and continuosly look for the closest waypoint.