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
Developer
abhay_401
Posts: 185
Registered: ‎09-02-2010
My Device: Not Specified

how to use google static maps in my application

hi all,

 

          In my application I want to use google static maps, and I want to display markers 

at my current location, are there any APIs to display google maps in blackberry.

 

       Please help me, its urgent

Developer
Developer
arv
Posts: 122
Registered: ‎08-11-2008
My Device: 9700

Re: how to use google static maps in my application

 

Hi ,

 

please take a look: http://www.coderholic.com/blackberry-webbitmapfield/

 

create an online web bitmap field,

the set the image URL to (for example static image with markers): 

http://maps.google.com/maps/api/staticmap?center=Brooklyn+Bridge,New+York,NY&zoom=14&size=512x512&ma...
&markers=color:blue|label:S|40.702147,-74.015794&markers=color:green|label:G|40.711614,-74.012318
&markers=color:red|color:red|label:C|40.718217,-73.998284&sensor=false

 

anyway, to get the current location, you can use GPS or Geolocation (LBS) from BlackBerry.

 

 

--
"Give kudos (star) if you feel response is helpful"
Developer
abhay_401
Posts: 185
Registered: ‎09-02-2010
My Device: Not Specified

Re: how to use google static maps in my application

hi,

 

        Thanks for ur quick reply, how ever I'm able to display the google static maps using that code. 

 

But how to repaint the map every time the user clicks track wheel. Each time the user clicks the 

 

trackwheel or track pad, I'm changing the lat/long value by one degree and calling that method again. The

 

map is updating, but how to get the smooth movement . 

 

         please help me...

Developer
simon_hain
Posts: 16,347
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: how to use google static maps in my application

you could look for transitions between the two bitmaps. discussed at length somewhere on the forum (use the search) and, since os 5, supported by the OS natively i think.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Developer
arv
Posts: 122
Registered: ‎08-11-2008
My Device: 9700

Re: how to use google static maps in my application

 

Hi ,

 

can you post code snippet or something?

 

From my point of view,

after you retrieved the image,

refresh the manager by calling method invalidate().

 

or after the user clicks the trackwheel,

redraw by delete the field and re-add the field.

 

 

--
"Give kudos (star) if you feel response is helpful"
Developer
abhay_401
Posts: 185
Registered: ‎09-02-2010
My Device: Not Specified

Re: how to use google static maps in my application

hi there,

 

        Below is the code I'm using to download the image. 

 

public Bitmap getImage(String mapurl) throws IOException
{
try
{
	ConnectionFactory connfac = new ConnectionFactory();
	ConnectionDescriptor conndesc;
	conndesc = connfac.getConnection(mapurl);
	if(conndesc!=null)
	{
		 hc = (HttpConnection)conndesc.getConnection();
		 final int responsecode = hc.getResponseCode();
			//Dialog.alert("response code"+Integer.toString(responsecode));
			DataInputStream iStrm = hc.openDataInputStream();
			ByteArrayOutputStream bStrm = null;
			 bitmap = null;
			byte imageData[];
			int length = (int) hc.getLength();
			if (length != -1)
			{
				imageData = new byte[length];
				iStrm.readFully(imageData);
			}
			else//Length not available...
			{
				bStrm = new ByteArrayOutputStream();
				int ch;
				while ((ch = iStrm.read()) != -1)
					bStrm.write(ch);
				imageData = bStrm.toByteArray();
				bStrm.close();
			}
			// Create the image from the byte array
			bitmap = Bitmap.createBitmapFromPNG(imageData, 0, imageData.length);
		}
	}

	catch(Exception e)
	{
		Dialog.alert(e.toString());
	}
	return (bitmap == null ? null : bitmap);
}

 

    I'm calling the below method when ever I need to repaint th map. The parameter lat and lon contains +/- 1 .

 

 

public void updateCoordinate(int lat, int lon)
{
	latt += 40.714728+lat;
	longg += -73.2541+lon;
	//Dialog.alert("coordinates....."+lat+lon);
	
	//Dialog.alert("lat..."+latt+"long...."+longg);
	url = "http://maps.google.com/maps/api/staticmap?center="+latt+","+longg+"&zoom=13&size=360x480&markers=color:blue|label:S|11211|11206|11222&sensor=true";	
	try 
	{
		bitmap = map.getImage(url);
		bmf.setBitmap(bitmap);
		//UiApplication.getUiApplication().repaint();
		
		
	} catch (IOException e) 
	{
		Dialog.alert(e.toString());
	}
	
}

 

 

In this way I'm trying to repaint the map, and the map is repainting. But the problem is, 

each time I'm repainting the map, lat and long are changing by one degree, so the map movement is not smooth. But I want the map to move smoothly.

 

       help me.........

 

regards,

 

 

 

Developer
simon_hain
Posts: 16,347
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: how to use google static maps in my application

http://supportforums.blackberry.com/t5/Java-Development/What-is-the-Event-Thread/ta-p/446865

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Developer
arv
Posts: 122
Registered: ‎08-11-2008
My Device: 9700

Re: how to use google static maps in my application

 

Hi ,

 

what do you mean with changing per one degree?

do you know that one degree in latitude and longitude is so wide?

 

what do you think about scrollable image field?

so you get a more wide image (than the Display),

to move more smooth you use the scrollable image field?

 

here is the reference: http://supportforums.blackberry.com/t5/Java-Development/Create-a-scrollable-image-field/ta-p/444955

--
"Give kudos (star) if you feel response is helpful"
Contributor
sparon
Posts: 45
Registered: ‎07-09-2013
My Device: Blackberry 9220

Re: how to use google static maps in my application

[ Edited ]

Hi ...

here where i will  call the

updateCoordinate() method?
Contributor
sparon
Posts: 45
Registered: ‎07-09-2013
My Device: Blackberry 9220

Re: how to use google static maps in my application

[ Edited ]

I am using your code.But i got error. What is the value of bmf?Where to get? where to declare map?