1

I copy, after setted api key( Should I generate a special key(browser,adnroid)?? ) , a html code of this page (Google Maps JavaScript API v3) in a new html page, and all works perfectlly.

This is a script of html page that works:

 <script type="text/javascript"
      src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCo1Q9VJ...xr7R4aOBDzY&sensor=false">
    </script>

On Worklight Prject, with Dojo, the maps isn't show.

I import the script with dojo/request/script . This is .js code:

     function dojoInit() {
            require([ "dojo",  "dojo/request/script","dojo/parser",

                   ..

                  ], function(dojo,script) {
    dojo.ready(script,function() {


                script.get({
                    url : "http://maps.googleapis.com/maps/api/js",
                    content : {
                        libraries : "places, geocode",
                        sensor : "false",
                        callback : "initialize",
                        key: "AIzaSyCo1Q9....cqXhAxr7R4aOBDzY"
                    }
                 });
    ...
            });
        });

    }

The initialize() function:

function initialize() {
    geocoder = new google.maps.Geocoder();
    var latlng = new google.maps.LatLng(-34.397, 150.644);
    var mapOptions = {
            zoom: 8,
            center: latlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
}   

build-dojo.xml

..
<include name="dojo/request/script.js" /> 

The view is empty and not display the map.

There are no errors on browser's console but the function initialize isn't call.Why?

Angelo
  • 814
  • 8
  • 21

3 Answers3

2

Use dojo io load to make sure the google api is loaded before running the rest of your code.

dojo.io.script.get({
            url : "http://maps.googleapis.com/maps/api/js",
            content : {
                libraries : "places, geocode",
                sensor : "false",
                callback : "initialize",
                key: "AIzaSyCo1Q9VJDuH96CqqW8cqXhAxr7R4aOBDzY"

            }
tik27
  • 2,698
  • 1
  • 16
  • 25
  • where i place this code?Because I insert it after dojo init function and the this error :"TypeError: dojo.io is undefined" show It's deprecated http://dojotoolkit.org/reference-guide/1.8/dojo/io/script.html – Angelo Jul 03 '13 at 15:49
  • dojo.io.script.get is deprecated . I use this http://dojotoolkit.org/reference-guide/1.9/dojo/request/script.html#dojo-request-script but don't work ! – Angelo Jul 05 '13 at 13:22
  • Error when it import "dojo/request/script", but i see that this file exists – Angelo Jul 05 '13 at 13:51
  • 1
    You will have to add it to the dojo build. find build-dojo.properties . Find the patternset tag. Add – tik27 Jul 05 '13 at 15:05
  • TypeError: script.get is not a function . – Angelo Jul 09 '13 at 15:59
1

also you need your require callback function to correctly map your require array arguments. Here it looks like you import several modules but you do only have 2 arguments to your require callback.

if you do

require(["a", "b", "c", "dojo/require/script"], ...)

the function should be

function(a, b, c, script) and not just function(a, script)

if you don't care about b & c you might do:

require(["a", "dojo/require/script", "b", "c"], function(a, script){});
Christophe
  • 736
  • 5
  • 15
1

I solved it by importing the script in html

    <script type="text/javascript"
          src="https://maps.googleapis.com/maps/api/js?key=AIzaS..OBDzY&sensor=false">
        </script> 
<div dojoType="dojox.mobile.ContentPane"  style="overflow:auto;">

        <div id="map_canvas" style="height:1000px"></div><!--  cambiare style  -->

    </div>

and calling the function initialize() in dojo_init(). The map is displayed as well enter image description here I think it's a CSS problem

Angelo
  • 814
  • 8
  • 21