Comparing Latitude and Longitude
In my iPad application 开发者_如何学Pythoni am drawing one rectangle on map using overlay. I have lat/long of one edge as well as length and width of rectangle.
I have some other lat/longs coming from database.Now how can i get which lat-long from database is inside rectangle?
Thanks,
Solved.
first of all convert four latlons to point using this method :
CGPoint point = [mapView convertCoordinate:location toPointToView:overlayView];
then you have to apply method of point in poly.
You can calculate the Distance and if Distance is greater then the current Lat-Long then it is out side otherwise it is inside the circle. You can calculate the Distance using the following lines.
CLLocation *location1 = [[CLLocation alloc] initWithLatitude:lat1 longitude:long1];
CLLocation *location2 = [[CLLocation alloc] initWithLatitude:lat2 longitude:long2];
NSLog(@"Distance i meters: %f", [location1 getDistanceFrom:location2]);
[location1 release];
[location2 release];
Try this
Please use the below code to get lat and long for touch point.
CGRect r = mapView.bounds;
float longitudePercent = overlay.point.x / r.size.width;
float latitudePercent = overlay.point.y / r.size.height;
CLLocationCoordinate2D coord = mapView.centerCoordinate;
MKCoordinateSpan span = mapView.region.span;
float lat = coord.latitude + (span.latitudeDelta/2);
float lon = coord.longitude - (span.longitudeDelta/2);
Just add your rectangle's length and width in overlay.point.x and overlay.point.y and get other lat and long.
after getting all 4 lat and long make a sql query on database and get related results for that.
精彩评论