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

Web and WebWorks Development

Reply
Regular Contributor
Posts: 65
Registered: ‎01-21-2011
My Device: Not Specified

Maps Integration Advice

Hi all, 

 

I'm after some advice / other peoples experience of integrating into the maps application from a web works app..

 

I've started from the point that i will have 1 line of an address, city and  postcode to work with from my available data and certainly do not have any long / lat coord's (if only, then life would be so simple Smiley Wink )

 

So for example i've got:

 

123 Letsbe Avenue

Sheffield

S1 1AA

 

and i know all my address are in the United Kingdom.

 

When i try and use the webworks API

 

Option 1:


blackberry.invoke.MapsArguments ( address : blackberry.pim.Address ) 

 

and create the pim address object i get an error that i can't create this without city and state... I

 

Issue 1: i don't have a state in my data

Issue 2: I don't live in america so don't have states so why is this mandatory Smiley Tongue Even if i put in a region for this say South Yorkshire to test it it still doesn't find my address...

 

So this pretty much rules out using that API.

 

Option 2:

Next i though i'd try the location document api. 

 

blackberry.invoke.MapsArguments ( locationDocument : String )

 

So did something like:

 

var locationDocument = "<?xml version='1.0'?><lbs><location address='123 Letsbe Avenue' postalCode='S1 1AA'></location></lbs>";
var mapArgs = new blackberry.invoke.MapsArguments(locationDocument);
blackberry.invoke.invoke(blackberry.invoke.APP_MAPS, mapArgs);

this just comes up with location not found all the time on the maps app.. (yes i am searching for a real address when i'm doing this Smiley Wink 

 

So i've had to resort to more drastic measures and try an extension using the JAVA api's.

 

First i tried

 

MapsArguments(String type, String what, String where) 

 

using ignoring the what and just specifying a where and this also returned location not found.

 

The only way i've got this to work is by using: 

 

MapsArguments(Contact contact, int addressIndex) 

 

creating a contact, not commiting it but passing that contact to the maps args........... SURELY I'm missing something here and there has to be a simpler way than going through all this faff..

 

 

Regular Contributor
Posts: 61
Registered: ‎08-11-2010
My Device: Not Specified

Re: Maps Integration Advice

[ Edited ]

Oh! I didnt know. Are we able to include and use Blackberry's Java APIs into the webworks app? Sorry if this question is too lame. But please throw some light. Smiley Happy

Regular Contributor
Posts: 65
Registered: ‎01-21-2011
My Device: Not Specified

Re: Maps Integration Advice

Yeah you can kick off the maps application using the java api's..

 

Have a look at the "creating a widget extension" tutorials give me a shout if you can't find them and i'll dig it out... That takes you through the simple code required to allow you to call the java stuff from javascript... Essentially it's a library.xml file which defines features you want to create e.g. my.mapslauncher ... this is them mapped upto a java class which extends net.rim.device.api.script.Scriptable and defines the fields you want to handle... e.g. my.mapslauncher.show(parameters here); then this mapping calls a class which extends import net.rim.device.api.script.ScriptableFunction and has a Invoke method which is called where you can do your java api version of spawning maps... 

 

e.g. 

 

 

public Object invoke(Object obj, Object[] args) throws Exception
	{
		if(args.length == 2)
		{
			String addressLine1 = (String)args[0];
			String postcode = (String)args[1];
			
			ContactList contacts = null;
			 try {
			     contacts = (ContactList) PIM.getInstance().openPIMList( PIM.CONTACT_LIST,
			             PIM.READ_WRITE );
			 } catch( PIMException e ) {
			     // An error occurred
			     return null;
			 }
			 Contact contact = contacts.createContact();
			 
			 String[] name = new String[ contacts.stringArraySize( Contact.NAME ) ];
			 name[ Contact.NAME_GIVEN ] = "TEMP";
			 name[ Contact.NAME_FAMILY ] = "TEMP";
			 
			 String[] addr = new String[ contacts.stringArraySize( Contact.ADDR ) ];
			 addr[ Contact.ADDR_COUNTRY ] = "United Kingdom";
			 addr[ Contact.ADDR_POSTALCODE ] = postcode;
			 addr[ Contact.ADDR_STREET ] = addressLine1;
			 
			 try {
			     contact.addStringArray( Contact.NAME, PIMItem.ATTR_NONE, name );
			     contact.addStringArray( Contact.ADDR, Contact.ATTR_HOME, addr );
			 
			 } catch( UnsupportedFieldException e ) {
			     // In this case, we choose not to save the contact at all if any of the
			     // fields are not supported on this platform.
			     System.out.println( "Contact not saved" );
			     return null;
			 }
			 
			MapsArguments mapsArgs = new MapsArguments(contact,0);
			Invoke.invokeApplication(Invoke.APP_TYPE_MAPS, mapsArgs);
		}
		return UNDEFINED;
	}
}

If you want a complete sample for the above give me a shout and I'll attach what I ended up with.

Retired
Posts: 1,382
Registered: ‎07-02-2009
My Device: BlackBerry Bold 9900
My Carrier: Bell

Re: Maps Integration Advice

[ Edited ]

As an FYI, I wanted to share that the full source code for the invoke and MapsArguments classes are now in Github (as of Tuesday this week).  This may serve as a helpful learning resource to understand what is happening under the covers, and perhaps how to overcome the issue of not being able to launch Maps to a UK address:

 

https://github.com/blackberry/WebWorks/tree/master/api/invoke/src/blackberry/invoke

 

 

In the meantime, I'm conferring with our test teams to see if I can get you a valid unit test that works for UK addresses.

 

Cheers,

Adam 

Follow me on Twitter: @n_adam_stanley
-------------------------------------------------------------------------------------------------------------------------
Your app doesn't work? Use BlackBerry remote web inspector to find out why.
Regular Contributor
Posts: 65
Registered: ‎01-21-2011
My Device: Not Specified

Re: Maps Integration Advice

[ Edited ]

Cheer I'll take a look at that Smiley Happy