Find Minimum/Maximum latitude and Longitude

与世无争的帅哥 提交于 2021-02-20 17:05:22

问题


My Question is how can i find minimum and maximum latitude and longitude of specific area (500 meter) from current location.

In my case, Such like i need to get X and Y CLLocation (latitude and longitude) from 500meter of area
See my image (sorry for this may be bad drawing )

enter image description here

I also have to tried to googling and i got link such like

How can i get minimum and maximum latitude and longitude using current location and radius?

But i don't know how it implement in my case.

Pleas help me in this issue.

NOTE : I do not want to use CLLocationDistance distance = [currentLocation distanceFromLocation:newLocation]; because it is not helpful in my case so..


回答1:


If you don't need a really precise value, then use the approximation that 1 degree is 111 km. Based on this, you need to add and remove 0.0025 degrees to the current coordinates to get corners of the area you are looking for.

rectanglesidelengthmeters = 500
degreedeltalat = 0.001 * (rectanglesidelengthmeters / 2.0) * cos(current.lon)
degreedeltalon = 0.001 * (rectanglesidelengthmeters / 2.0) * cos(current.lat)
minlat = current.lat - degreedeltalat
maxlat = current.lat + degreedeltalat
minlon = current.lon - degreedeltalon
maxlon = current.lon + degreedeltalon

You may need to correct the result a little for staying in the -90 .. 90 range for latitude and -180 .. 180 range for longitude values but I think CLClocation will handle that for you too.




回答2:


You have to do some radius calculation from current location in km.

double kilometers = 0.5;
double curve = ABS( (cos(2 * M_PI * location.coordinate.latitude / 360.0) ));

MKCoordinateSpan span; 

span.latitudeDelta = kilometers/111; //like allprog said.
span.longitudeDelta = kilometers/(curve * 111); 

MKCoordinateRegion region;
region.span = span;
region.center = location.coordinate;

[self.mapView setRegion:region animated:YES];

This way i set mapView to show distance region to 0.5 km.

EDIT: Whoa, i digging in my old 'liked' question to show you some original answer, but found a better one below accepted one:

how to make mapview zoom to 5 mile radius of current location

Look at @Anurag answer




回答3:


To get precise value you should try with

minLattitude = currentLattitude - (RadiusInKm/111.12);
maxLattitude = currentLattitude + (RadiusInKm/111.12);

Thus in your case RadiusInKm = 0.5

For finding in & max longitude data you need to follow the same thing but but you have to multiply the result with cosine function of latitude




回答4:


I would do this way.

double accuracy = 0.1;//How accurate do you want. Smaller value, slower perform
double distance = 500;//Distance you want
  1. Create infinite loop.
  2. In the loop check whether distance is bigger than 500. If yes, break. If not, add 0.1 value to latitude or longitude.
  3. Do above way to get Max longitude, max latitude, min longitude and min latitude.
  4. Compare your DB, if CLLocation is inside of the value, then return.

I cannot say this is the best way to solve your problem. Because we are guessing value...If you know how to convert CLLocation from given distance, that is better!




回答5:


This should be correct (in php)
https://www.movable-type.co.uk/scripts/latlong-db.html

$R = 6371;  // earth's mean radius, km
$rad = 0.5

// first-cut bounding box (in degrees)
$maxLat = $lat + rad2deg($rad/$R);
$minLat = $lat - rad2deg($rad/$R);
$maxLon = $lon + rad2deg(asin($rad/$R) / cos(deg2rad($lat)));
$minLon = $lon - rad2deg(asin($rad/$R) / cos(deg2rad($lat)));


来源:https://stackoverflow.com/questions/18696441/find-minimum-maximum-latitude-and-longitude

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!