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
Contributor
Posts: 41
Registered: ‎05-03-2012
My Device: Blackberry 10 Alpha, Blackberry Bold 9930
My Carrier: Fido

WebWorks and Maps

Hey guys, I'm fairly new to Blackberry development, so forgive me if my questions are quite...simple.

 

Anyways, I'm a co-op student and I was recently assigned to port over an app from BB7 to BB10. I'm trying to do it multi-platform, so i'm using the WebWorks SDK to try and accomplish my goals.

 

My app requires the geolocation, and also to be able to show the location on a map. I have the geolocation down right; if I do:

 

alert("Latitude: " + lat + " Longitude: " + lon);

 it will show the correct co-ordinates. The only problem is, I can't seem to initalize a map...in the Ripple simulator, all I'm getting is a big blank screen where the map is supposed to be. I'm initializing the map like this:

function showMap(lat, lon)
{
	blackberry.launch.newMap({
	"latitude":lat, "longitude": lon});
}

 I'm probably doing something wrong here; anybody have pointers?

 

Developer
Posts: 214
Registered: ‎01-07-2011
My Device: Bold 9900
My Carrier: Rogers

Re: WebWorks and Maps

Are you pulling the map from an external source? If yes, have you added the access permission for the domain you are trying to acces?

<access subdomains="true" uri="http://domain.com"/>

 Documentation for access element (http://glpr.ca/K5zSvN)

--
Rory (@roryboy)
Click "Accept as Solution" if post solved your original issue. Give like/thumbs up if you feel post is helpful
Contributor
Posts: 41
Registered: ‎05-03-2012
My Device: Blackberry 10 Alpha, Blackberry Bold 9930
My Carrier: Fido

Re: WebWorks and Maps

Hmm, i haven't actually tried to get a map from an external source, i've been trying to use the built-in Maps function. But from going over the API, it looks like that's what I'll ave to do. 

 

I'll give us an external source a shot!

 

Thanks!

Contributor
Posts: 41
Registered: ‎05-03-2012
My Device: Blackberry 10 Alpha, Blackberry Bold 9930
My Carrier: Fido

Re: WebWorks and Maps

Hmm, still nothing; all I have is a big empty space where my map should be. I think I've done everything correctly; in fact, I've just been pulling off code from google and RIM's own tutorials, but nothing seems to work.

 

Any other suggestions?

Developer
Posts: 35
Registered: ‎05-20-2011
My Device: Z10 and 32GB Playbook
My Carrier: O2 UK

Re: WebWorks and Maps

If you wish to launch BB Maps with coordinates you can use:

 

function showmap(lat,lon)	{

var args = new blackberry.invoke.MapsArguments(lat, lon);
blackberry.invoke.invoke(blackberry.invoke.APP_MAPS, args);
			 }
		

 I have, however, ran into problems if this is packaged using webworks SDK 2.3.1.5 but it will work fine with v2.1.1

Contributor
Posts: 41
Registered: ‎05-03-2012
My Device: Blackberry 10 Alpha, Blackberry Bold 9930
My Carrier: Fido

Re: WebWorks and Maps

I've actually tried that...my code looks like this:

 

function initialize()
{
//First test to see that the browser supports the Geolocation API
   if (navigator.geolocation !== null)
   {
      navigator.geolocation.getCurrentPosition(geolocationSuccess, geolocationError, geolocationOptions);
   }
   else {
      alert("HTML5 geolocation is not supported.");
   }
}

function geolocationError(error)
{
	alert("An unexpected error occurred [" + error.code + "]: " + error.message);
}

function showMap(lat, lon)
{
    var args = new blackberry.invoke.MapsArguments(lat, lon);
    blackberry.invoke.invoke(blackberry.invoke.APP_MAPS, args);
}

function geolocationSuccess(position)
{
   //Extract information about the users current position:
   var time = position.timestamp;
   var coordinates = position.coords;

   //Retrieve geographic information about the GPS fix:
   var lat = coordinates.latitude;
   var lon = coordinates.longitude;
   var alt = coordinates.altitude;
   var acc = coordinates.accuracy;
   var altAcc = coordinates.altitudeAccuracy;
   var head = coordinates.heading;
   var speed = coordinates.speed;
   showMap(lat, lon);
}

 so, i actually call the showMap function inside my geolocationSuccess one...but once again, i get nothing but a blank screen

Highlighted
Developer
Posts: 35
Registered: ‎05-20-2011
My Device: Z10 and 32GB Playbook
My Carrier: O2 UK

Re: WebWorks and Maps

OK, try this:

<!DOCTYPE HTML> 
<html>
<head>
	<title></title>
	<meta id="viewport" name="viewport" content="user-scalable=no, width=device-width" />
<script language="javascript">
function getPosition(params)
{
		if (navigator.geolocation !== null)
		{
			options = { enableHighAccuracy : true, maximumAge : 0 };
			navigator.geolocation.getCurrentPosition(geolocationSuccess, geolocationError, options);
		} 
		else {
			errorMessage("Geolocation is not supported.");
		}
	} 

function geolocationError(Error)
{
	alert("ERROR");
}

function geolocationSuccess(position) 
{
		var coordinates = position.coords;
		showmap(coordinates);
}

function showmap(coordinates)
{
		var lat = coordinates.latitude;
		var lon = coordinates.longitude;
		var args = new blackberry.invoke.MapsArguments(lat, lon);
   		blackberry.invoke.invoke(blackberry.invoke.APP_MAPS, args);
}
</script>
</head>
<html>
<body onload="getPosition();">
</body> 
</html>

 

and don't forget you need the following feature elements in config.xml:

 

<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns="http://www.w3.org/ns/widgets" version="1.3.0.0">
	<name>GeoTest</name>
	<description>GeoTest</description>
	<author></author>
	<icon src="icon.png"/>
	<content src="index.html"/>
	<feature id="blackberry.invoke" />
    <feature id="blackberry.invoke.MapsArguments" />
    <license href="http://www.apache.org/licenses/LICENSE-2.0">
	</license>
</widget>

 

HTH