Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Regular Contributor
Posts: 95
Registered: ‎07-16-2010
My Device: 8520
My Carrier: bsnl

find center of map and according zoom level

hello,

 

i need to implement map.

now i have many location to mark on map so after put location i want map move over there in center and set zoom level related so all mark location display.

 

1)i doinng on way like find first center location

2)move map on center location

3)call set location fo find related zoom level

 

INITIAL ZOOM LEVEL = 1;

 

code to find center location referlink    http://www.geomidpoint.com/example.html

in bellow calculation take w=1 (i dont understand how to get w so as per link note i take =1 )

 

public static MapLocation CaculateMidPoint(MapLocation[] arrmaplocation)
	{
		double X=0,Y=0,Z=0,Lon=0,Lat=0.0,hyp=0,xi=0,yi=0,zi=0,lat1=0,lon1=0;
		final double PI=3.1428571;
		int L=arrmaplocation.length;
		for(int i=0;i<L;i++)
		{
			lat1=(arrmaplocation[i].getLatitude()*PI)/180;
			lon1=(arrmaplocation[i].getLongitude()*PI)/180;
			xi = Math.cos(lat1)*Math.cos(lon1);
			yi = Math.cos(lat1) *Math.sin(lon1);
			zi = Math.sin(lat1);
			X=X+xi;
			Y=Y+yi;
			Z=Z+zi;
		}
		X=X/L;
		Y=Y/L;
		Z=Z/L;
		Lon = atan2(Y,X);
		hyp = Math.sqrt(X*X+Y*Y);
		Lat = atan2(Z, hyp);
		Lat = Lat * 180/PI;
		Lon = Lon * 180/PI;
		
		return new MapLocation(Lat, Lon, "");
	}

 

and to setzoom level in that m=current location and marr is marked location

 

private void setZoomLevel(MapLocation m, MapLocation[] marr) 
	{
		XYPoint xy = new XYPoint();
		XYPoint[] mxy = new XYPoint[marr.length];

		boolean mapzoom=true;

		while(mapzoom)
		{
			convertWorldToField(m,xy);
			boolean noforloop=true;
			for(int i=0;i<marr.length;i++)
			{
				if(mxy[i]==null)
					mxy[i]=new XYPoint();
				convertWorldToField(marr[i],mxy[i]);

				double ax=(xy.x-mxy[i].x);
				double ay=(xy.y-mxy[i].y);
				if(ax<0) 
					ax=ax*(-1);
				if(ay<0) 
					ay=ay*(-1);
				if(ax>(width-10)/2 && ay>(height-10)/2)
				{
					noforloop=false;
					INITIAL_ZOOM=INITIAL_ZOOM+1;
					if(INITIAL_ZOOM>=15)
					{
						mapzoom=false;
						noforloop=true;
					}
					setZoom(INITIAL_ZOOM);
					break;
				}
			}
			if(noforloop)
			{
				break;
			}
			//			System.out.println("------------"+xy.x+"<->"+xy1.x+"----,---"+xy.y+"<->"+xy1.y);
			//			System.out.println("------------"+ax+"<->"+width+"----,---"+ay+"<->"+height);

		}
	}

 

 

in that mid point location gives wrong i am use below latlong

 

25.258746
55.319595

25.278746
55.32053

and center is ==> 25.34339018942216

                                 55.17422770053354

 

such mesh things................!

 

is there blackberry provide any things like bound function in Android map?

 

please help as well blackberry to improve map thanks in advance,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,!

 

 

Highlighted
Regular Contributor
Posts: 95
Registered: ‎07-16-2010
My Device: 8520
My Carrier: bsnl

Re: find center of map and according zoom level

now mu code is wprking

 

few of my mistake below

 

1)atan2(Y,X) replace with MathUtility.atan2(Y,X)  everyplace

 

2)Lat = Lat * 180/PI;  replace with Lat=Math.Toredian(Lat) enerywhere where need to conver in redian

 

3) in zoom function i) before call zoom set zoom level =1

                                   ii)if(ax>(width-10)/2 && ay>(height-10)/2)   replace with if(ax>(width/2) || ay>(height/2))

 

now map gives approx correct result