android - Get Northeast and Southwest from skmaps -


hi i'm porting app google maps skmaps. api require northeast , southwest points, in skmaps can't find way points. tried onmapregionchangeended interface method, returned map's center point , zoom level.

how can it?

i did next workaround based on c# code bounds google's static maps. yet must improve zoom ranges work skmaps.

public class mapsutils {      public static int tilesize = 256;     public static double originx, originy;     public static double pixelsperlondegree;     public static double pixelsperlonradian;      public static void mapsutils() {         originx = tilesize / 2;         originy = tilesize / 2;         pixelsperlondegree = tilesize / 360.0;         pixelsperlonradian = tilesize / (2 * math.pi);     }      public static double degreestoradians(double deg) {         return deg * math.pi / 180.0;     }      public static double radianstodegrees(double rads) {         return rads * 180.0 / math.pi;     }      public static double bound(double value, double min, double max) {         value = math.min(value, max);         return math.max(value, min);     }      //from lat, lon world coordinate x, y. i'm being explicit in assigning //x , y properties.     public static coordinate mercator(double latitude, double longitude) {         double siny = bound(math.sin(degreestoradians(latitude)), -.9999, .9999);          coordinate c = new coordinate();         c.setx(originx + longitude * pixelsperlondegree);         c.sety(originy + .5 * math.log((1 + siny) / (1 - siny)) * -pixelsperlonradian);          return c;     }      //from world coordinate x, y lat, lon. i'm being explicit in assigning     //latitude , longitude properties.     public static coordinate inversemercator(double x, double y) {         coordinate c = new coordinate();          c.setlongitude((x - originx) / pixelsperlondegree);         double latradians = (y - originy) / -pixelsperlonradian;         c.setlatitude(radianstodegrees(math.atan(math.sinh(latradians))));          return c;     }      public static mapbound getbound(coordinate center,int zoom,int mapwidth,int mapheight){         mapsutils.mapsutils();         double scale = math.pow(2, zoom);          coordinate centerworld = mercator(center.getlatitude(), center.getlongitude());         coordinate centerpixel = new coordinate();         centerpixel.setx(centerworld.getx() * scale);         centerpixel.sety(centerworld.gety() * scale);          coordinate nepixel = new coordinate();         nepixel.setx(centerpixel.getx() + mapwidth / 2.0);         nepixel.sety(centerpixel.gety() - mapheight / 2.0);          coordinate swpixel = new coordinate();         swpixel.setx(centerpixel.getx() - mapwidth / 2.0);         swpixel.sety(centerpixel.gety() + mapheight / 2.0);          coordinate neworld = new coordinate();         neworld.setx(nepixel.getx() / scale);         neworld.sety(nepixel.gety() / scale);          coordinate swworld = new coordinate();         swworld.setx(swpixel.getx() / scale);         swworld.sety(swpixel.gety() / scale);          coordinate nelatlon = inversemercator(neworld.getx(), neworld.gety());         coordinate swlatlon = inversemercator(swworld.getx(), swworld.gety());          return new mapbound(nelatlon,swlatlon);     }   } 

mapbound class:

public class mapbound {     private coordinate northeast, southwest;      public mapbound(coordinate northeast, coordinate southwest) {         this.northeast = northeast;         this.southwest = southwest;     }      public coordinate getnortheast() {         return northeast;     }      public void setnortheast(coordinate northeast) {         this.northeast = northeast;     }      public coordinate getsouthwest() {         return southwest;     }      public void setsouthwest(coordinate southwest) {         this.southwest = southwest;     } } 

and coordinate class:

public class coordinate{     private double x,y,latitude, longitude;      public coordinate() {         this.x = 0;         this.y = 0;     }      public coordinate(double latitude, double longitude) {         this.latitude = latitude;         this.longitude = longitude;     }      public double getx() {         return x;     }      public void setx(double x) {         this.x = x;     }      public double gety() {         return y;     }      public void sety(double y) {         this.y = y;     }      public double getlatitude() {         return latitude;     }      public void setlatitude(double latitude) {         this.latitude = latitude;     }      public double getlongitude() {         return longitude;     }      public void setlongitude(double longitude) {         this.longitude = longitude;     } } 

for use code:

@override public void onmapregionchangeended(skcoordinateregion skcoordinateregion) {     mapbound mapbound = mapsutils.getbound(             new coordinate(skcoordinateregion.getcenter().getlatitude(), skcoordinateregion.getcenter().getlongitude()),             (int) skcoordinateregion.getzoomlevel(),             skmap.getwidth(),             skmap.getheight());     mapbound.getnortheast().getlatitude();     mapbound.getnortheast().getlongitude();     mapbound.getsouthwest().getlatitude();     mapbound.getsouthwest().getlongitude();    } 

Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -