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
Contributor
sukanyak
Posts: 21
Registered: ‎07-10-2013
My Device: Blackberry simlator 9220

Re: Static map API

without GPS activation , how to use that?

Developer
developer_aman_arora
Posts: 354
Registered: ‎06-05-2013
My Device: Blackberry Z10

Re: Static map API

Not possible without GPS.
Study GPS to make it more clear..
Contributor
sukanyak
Posts: 21
Registered: ‎07-10-2013
My Device: Blackberry simlator 9220

Re: Static map API

ok... thank you very much...

Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: Static map API

Just going to summarize where we are.

 

The static maps API is documented here:

https://developers.google.com/maps/documentation/staticmaps/index

 

You can use this in two ways:

a) create your URL and use this is a BrowserField - so the BrowserField will download and display the image, or

b) download the image yourself and display it - this is more flexible but means you will have to write networking code, which people normally struggle with.

 

Finding your location can be achieved using any of the Location Services that is provided on your device.  Which ones are supported depends on your OS level primarily, but may also vary depending on your carrier and plan.  But you can find a location without using GPS (without using the satellites) on most phones.  For more information, I suggest these links:

http://supportforums.blackberry.com/t5/Java-Development/Location-APIs-Start-to-finish/ta-p/571949

http://devblog.blackberry.com/2011/07/simple-location-api/

 

I hope this clarifies what you can do.

 

Good luck trying it!

Contributor
sukanyak
Posts: 21
Registered: ‎07-10-2013
My Device: Blackberry simlator 9220

Re: Static map API

//Im this code GPS are used?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????






















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); }

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());
	}
	
}
Contributor
sukanyak
Posts: 21
Registered: ‎07-10-2013
My Device: Blackberry simlator 9220

Re: Static map API

how to retrive url in blackberry application.I dono how to get the map?

Contributor
sparon
Posts: 45
Registered: ‎07-09-2013
My Device: Blackberry 9220

Re: Static map API

[ Edited ]

I dono, what mistake i did? But,I got error.I didnt get url response code and image.Please if anyone know then tell me.

 

 

 

httpConn =(HttpsConnection)Connector.open("http://maps.googleapis.com/maps/api/staticmap?center=New+York,NY&zoom=13&size=100x100&key=AIzaSyCZ69...
int rc = httpConn.getResponseCode();
Dialog.alert("response:" + rc );
if (rc != HttpsConnection.HTTP_OK) {
Dialog.alert("HTTP response code: " + rc);
}
InputStream input = httpConn.openInputStream();
byte[] dataArray = net.rim.device.api.io.IOUtilities.streamToBytes(input);
googleImage = Bitmap.createBitmapFromBytes(dataArray, 0, -1, 1);
BitmapField bmf= new BitmapField(googleImage);
add(bmf);
}
catch (IOException e)
{
e.printStackTrace();
}

Developer
developer_aman_arora
Posts: 354
Registered: ‎06-05-2013
My Device: Blackberry Z10
Developer
developer_aman_arora
Posts: 354
Registered: ‎06-05-2013
My Device: Blackberry Z10

Re: Static map API

You have to remove ",Connector.READ_WRITE);" from your url thats why it is not working?
Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: Static map API

@developer_aman_arora: The

",Connector.READ_WRITE"

is actually a parameter to the Connector open method.  So this has nothing to do with the reason the code is not working.

 

@sparon.  As I mentione in my summary above, networking on the Blackberry is complicated.  I don't have tme to do into it atm.  For now I recommend you review the httpDemo sample and that you review the followng KB articles to help you understand it better.

 

http://supportforums.blackberry.com/t5/Java-Development/Networking-Transports-II/ta-p/446742

 

http://supportforums.blackberry.com/t5/Java-Development/What-Is-Network-API-alternative-for-legacy-O...

 

I recommend that you also investigate ConnectionFactory, which can make this process much easier.

 

There are many Threads on this forum that will help you with netoworking issues.  Search. 

 

Finally you said But,I got error"".  When you get an error, please report what it is.  Otherwise we are just guessing.