Created
December 9, 2014 19:31
-
-
Save carlosmuvi/ffc760ef2d01efa6dffd to your computer and use it in GitHub Desktop.
prueba
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Transforms circle coordinates into bounds for camera movement | |
* | |
* @param center | |
* @param latDistanceInMeters | |
* @param lngDistanceInMeters | |
* @return | |
*/ | |
public static LatLngBounds boundsWithCenterAndLatLngDistance(LatLng center, | |
float latDistanceInMeters, float lngDistanceInMeters) { | |
latDistanceInMeters /= 2; | |
lngDistanceInMeters /= 2; | |
LatLngBounds.Builder builder = LatLngBounds.builder(); | |
float[] distance = new float[1]; | |
{ | |
boolean foundMax = false; | |
double foundMinLngDiff = 0; | |
double assumedLngDiff = ASSUMED_INIT_LATLNG_DIFF; | |
do { | |
Location.distanceBetween(center.latitude, center.longitude, | |
center.latitude, center.longitude + assumedLngDiff, | |
distance); | |
float distanceDiff = distance[0] - lngDistanceInMeters; | |
if (distanceDiff < 0) { | |
if (!foundMax) { | |
foundMinLngDiff = assumedLngDiff; | |
assumedLngDiff *= 2; | |
} else { | |
double tmp = assumedLngDiff; | |
assumedLngDiff += (assumedLngDiff - foundMinLngDiff) / 2; | |
foundMinLngDiff = tmp; | |
} | |
} else { | |
assumedLngDiff -= (assumedLngDiff - foundMinLngDiff) / 2; | |
foundMax = true; | |
} | |
} while (Math.abs(distance[0] - lngDistanceInMeters) > lngDistanceInMeters | |
* ACCURACY); | |
LatLng east = new LatLng(center.latitude, center.longitude | |
+ assumedLngDiff); | |
builder.include(east); | |
LatLng west = new LatLng(center.latitude, center.longitude | |
- assumedLngDiff); | |
builder.include(west); | |
} | |
{ | |
boolean foundMax = false; | |
double foundMinLatDiff = 0; | |
double assumedLatDiffNorth = ASSUMED_INIT_LATLNG_DIFF; | |
do { | |
Location.distanceBetween(center.latitude, center.longitude, | |
center.latitude + assumedLatDiffNorth, | |
center.longitude, distance); | |
float distanceDiff = distance[0] - latDistanceInMeters; | |
if (distanceDiff < 0) { | |
if (!foundMax) { | |
foundMinLatDiff = assumedLatDiffNorth; | |
assumedLatDiffNorth *= 2; | |
} else { | |
double tmp = assumedLatDiffNorth; | |
assumedLatDiffNorth += (assumedLatDiffNorth - foundMinLatDiff) / 2; | |
foundMinLatDiff = tmp; | |
} | |
} else { | |
assumedLatDiffNorth -= (assumedLatDiffNorth - foundMinLatDiff) / 2; | |
foundMax = true; | |
} | |
} while (Math.abs(distance[0] - latDistanceInMeters) > latDistanceInMeters | |
* ACCURACY); | |
LatLng north = new LatLng(center.latitude + assumedLatDiffNorth, | |
center.longitude); | |
builder.include(north); | |
} | |
{ | |
boolean foundMax = false; | |
double foundMinLatDiff = 0; | |
double assumedLatDiffSouth = ASSUMED_INIT_LATLNG_DIFF; | |
do { | |
Location.distanceBetween(center.latitude, center.longitude, | |
center.latitude - assumedLatDiffSouth, | |
center.longitude, distance); | |
float distanceDiff = distance[0] - latDistanceInMeters; | |
if (distanceDiff < 0) { | |
if (!foundMax) { | |
foundMinLatDiff = assumedLatDiffSouth; | |
assumedLatDiffSouth *= 2; | |
} else { | |
double tmp = assumedLatDiffSouth; | |
assumedLatDiffSouth += (assumedLatDiffSouth - foundMinLatDiff) / 2; | |
foundMinLatDiff = tmp; | |
} | |
} else { | |
assumedLatDiffSouth -= (assumedLatDiffSouth - foundMinLatDiff) / 2; | |
foundMax = true; | |
} | |
} while (Math.abs(distance[0] - latDistanceInMeters) > latDistanceInMeters | |
* ACCURACY); | |
LatLng south = new LatLng(center.latitude - assumedLatDiffSouth, | |
center.longitude); | |
builder.include(south); | |
} | |
return builder.build(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment