Back to project page android-gmaps-addons.
The source code is released under:
Copyright (c) 2014 Jonathan Baker Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Sof...
If you think the Android project android-gmaps-addons listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.cocoahero.android.gmaps.addons.util; /*from w w w. j av a 2 s .c o m*/ import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.LatLngBounds; import com.google.android.gms.maps.model.PolygonOptions; public class LatLngBoundsUtils { /** * Calculates the center coordinate of a {@link LatLngBounds}. * * @param bounds A {@link LatLngBounds} instance. * @return the center coordinate of the given bounds. */ public static LatLng getCenter(LatLngBounds bounds) { double n = bounds.northeast.latitude; double e = bounds.northeast.longitude; double s = bounds.southwest.latitude; double w = bounds.southwest.longitude; double lat = ((n + s) / 2.0); double lon = ((e + w) / 2.0); return new LatLng(lat, lon); } /** * Creates a {@link PolygonOptions} instance configured to visualize a * {@link LatLngBounds}. * * @param bounds A {@link LatLngBounds} instance. * @return a {@link PolygonOptions} instance configured to visualize a * {@link LatLngBounds}. */ public static PolygonOptions toPolygonOptions(LatLngBounds bounds) { double n = bounds.northeast.latitude; double e = bounds.northeast.longitude; double s = bounds.southwest.latitude; double w = bounds.southwest.longitude; LatLng ne = new LatLng(n, e); LatLng nw = new LatLng(n, w); LatLng sw = new LatLng(s, w); LatLng se = new LatLng(s, e); PolygonOptions opts = new PolygonOptions(); opts.add(ne); opts.add(nw); opts.add(sw); opts.add(se); return opts; } }