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

Native Development

Reply
Developer
Posts: 232
Registered: ‎01-30-2011
My Device: Dev Alpha C, Z10 LE
My Carrier: P4
Accepted Solution

WebView and double property

I have property: 

property double lon: 18.612492

 and webView with html:

'<!DOCTYPE html><html><head>
<meta charset="UTF-8" />
<title>' + "Last sent" + '</title>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
</head><body>

<div id="mini-map" style="display: block; width: 662px; height: 468px;"></div>
<script type="text/javascript">
	var mapOptions = {
		zoom: 18,
		center: new google.maps.LatLng("' + lon.toFixed(4) + '", 25.4),
		mapTypeId: google.maps.MapTypeId.ROADMAP
	};
	map = new google.maps.Map(document.getElementById("mini-map"), mapOptions);
	var marker=new google.maps.Marker({
		position: new google.maps.LatLng(0.0, 0.0),
		map: map,
		title: "'+"Last sent"+'"
	});
</script>
</body></html>'

it doesn't work...

 

 When I change 11. line to:

center: new google.maps.LatLng("18.62", 25.4),

 everything works fine...

 

How can I put double property into html code?

All time online Smiley Very Happy
Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: WebView and double property

How do you set this text?

 

This code gives me a syntax error on console.log() line. lon.toFixed(4) returns correct value though. Have you tried printing the result before assigning it to WebView?

 

        Button {
            text: "Test"
            onClicked: {
                console.log('<!DOCTYPE html><html><head>
                <meta charset="UTF-8" />
                <title>' + "Last sent" + '</title>
                <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
                </head><body>
                
                <div id="mini-map" style="display: block; width: 662px; height: 468px;"></div>
                <script type="text/javascript">
                	var mapOptions = {
                		zoom: 18,
                		center: new google.maps.LatLng("' + lon.toFixed(4) + '", 25.4),
                		mapTypeId: google.maps.MapTypeId.ROADMAP
                	};
                	map = new google.maps.Map(document.getElementById("mini-map"), mapOptions);
                	var marker=new google.maps.Marker({
                		position: new google.maps.LatLng(0.0, 0.0),
                		map: map,
                		title: "'+"Last sent"+'"
                	});
                </script>
                </body></html>')
            } 
        }

 


Andrey Fidrya, @zmeyc on twitter
Developer
Posts: 232
Registered: ‎01-30-2011
My Device: Dev Alpha C, Z10 LE
My Carrier: P4

Re: WebView and double property

Just solved: QML don't like multiline strings.

 

Correct way (in my html for webView) is:

'<!DOCTYPE html><html><head>'+
'<meta charset="UTF-8" />'+
'<title>' + "Last sent" + '</title>'+
'<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>'+
'</head><body>'+

'<div id="mini-map" style="display: block; width: 662px; height: 468px;"></div>'+
'<script type="text/javascript">'+
	'var mapOptions = {'+
	'	zoom: 18,'+
	'	center: new google.maps.LatLng("' + lon.toFixed(4) + '", 25.4),'+
	'	mapTypeId: google.maps.MapTypeId.ROADMAP'+
	'};'+
	'map = new google.maps.Map(document.getElementById("mini-map"), mapOptions);'+
	'var marker=new google.maps.Marker({'+
	'	position: new google.maps.LatLng(0.0, 0.0),'+
	'	map: map,'+
	'	title: "'+"Last sent"+'"'+
	'});'+
'</script>'+
'</body></html>'

 

All time online Smiley Very Happy