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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Highlighted
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,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,!

 

 

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