下面列出了怎么用com.google.android.gms.maps.model.VisibleRegion的API类实例代码及写法,或者点击链接到github查看源代码。
public void moveCameraByDevice() {
LatLng latLng = getDevLocation();
if (latLng != null) {
float zoom = this.mGoogleMap.getCameraPosition().zoom;
VisibleRegion visibleRegion = this.mGoogleMap.getProjection().getVisibleRegion();
LatLng farLeft = visibleRegion.farLeft;
LatLng nearRight = visibleRegion.nearRight;
Point point = this.mGoogleMap.getProjection().toScreenLocation(latLng);
Point topLeft = this.mGoogleMap.getProjection().toScreenLocation(farLeft);
Point bottomRight = this.mGoogleMap.getProjection().toScreenLocation(nearRight);
boolean b = topLeft.x <= point.x && point.x <= bottomRight.x && topLeft.y <= point.y && point.y <= bottomRight.y;
if (!b) {
this.mGoogleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, zoom));
}
}
}
protected void setExtents() {
if (map != null) {
VisibleRegion region = map.getProjection().getVisibleRegion();
double ullon = region.farLeft.longitude;
double ullat = region.farLeft.latitude;
double lrlon = region.nearRight.longitude;
double lrlat = region.nearRight.latitude;
//set the geo extents
utility.SetExtents(ullon, lrlon, ullat, lrlat);
//set the pixels extents
android.graphics.Point ul = map.getProjection().toScreenLocation(region.farLeft);
android.graphics.Point lr = map.getProjection().toScreenLocation(region.nearRight);
double width = lr.x - ul.x;
double height = lr.y - ul.y;
utility.set_displayPixelsWidth(width);
utility.set_displayPixelsHeight(height);
}
return;
}
public void addPolylinescircle(boolean cw, double lat, double lng, double lat1, double lng2, int radius, int maxRadius) {
if (this.line != null) {
this.line.remove();
this.line = null;
}
FLatLng centerpoint = GpsCorrect.Earth_To_Mars(lat, lng);
FLatLng point = GpsCorrect.Earth_To_Mars(lat1, lng2);
float angle = this.mapCalcAngle.getAngle2(new LatLng(centerpoint.latitude, centerpoint.longitude), new LatLng(point.latitude, point.longitude));
PolylineOptions options = new PolylineOptions();
int time = (int) Math.round((((double) (radius * 2)) * 3.141592653589793d) / 10.0d);
if (time < 50) {
time = 50;
} else if (time > 180) {
time = 180;
}
double temp = (double) ((((float) ((maxRadius + 10) - radius)) * 1.0f) / ((float) time));
VisibleRegion visibleRegion = this.googleMap.getProjection().getVisibleRegion();
LatLng farLeft = visibleRegion.farLeft;
LatLng nearRight = visibleRegion.nearRight;
float scale = GeoTools.getScale(farLeft, nearRight, this.googleMap.getProjection().toScreenLocation(nearRight).x - this.googleMap.getProjection().toScreenLocation(farLeft).x);
for (int i = 0; i < 360; i++) {
float startAngle;
float t = (float) (((double) scale) * (((double) radius) + (((double) (((float) i) / (360.0f / ((float) time)))) * temp)));
if (cw) {
startAngle = ((float) i) + angle;
} else {
float cc = angle - ((float) i);
if (cc < 0.0f) {
startAngle = 360.0f + cc;
} else {
startAngle = cc;
}
}
Point p1 = this.googleMap.getProjection().toScreenLocation(new LatLng(centerpoint.latitude, centerpoint.longitude));
options.add(this.googleMap.getProjection().fromScreenLocation(new Point((int) (((double) p1.x) + (((double) t) * Math.cos((((double) startAngle) * 3.141592653589793d) / 180.0d))), (int) (((double) p1.y) + (((double) t) * Math.sin((((double) startAngle) * 3.141592653589793d) / 180.0d))))));
}
this.line = this.googleMap.addPolyline(options.width(3.0f));
this.line.setColor(this.context.getResources().getColor(R.color.x8_drone_inface_line));
}
ClustersBuilder(Projection projection, Options options, ArrayList<ClusterPoint> initialClusteredPoints) {
this.options = options;
this.projectionRef = new WeakReference<Projection>(projection);
this.visibleRegionRef = new WeakReference<VisibleRegion>(projection.getVisibleRegion());
if (initialClusteredPoints != null) {
addRelevantInitialInputPoints(initialClusteredPoints);
}
}
void addAll(ArrayList<InputPoint> points) {
if (points != null) {
Projection projection = getProjection();
VisibleRegion visibleRegion = getVisibleRegion();
if (projection != null && visibleRegion != null) {
LatLngBounds bounds = getExpandedBounds(visibleRegion.latLngBounds);
for (InputPoint point : points) {
addIfNecessary(point, projection, bounds);
}
}
}
}
@Override
public VisibleRegion getVisibleRegion() throws RemoteException {
viewport.getMapExtents(extents, 0);
// TODO: Support non-flat map extents
return new VisibleRegion(GmsMapsTypeHelper.toLatLngBounds(viewport.getBBox(null, 0)));
}
private VisibleRegion getVisibleRegion() {
return visibleRegionRef.get();
}