Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught InvalidValueError: setMap: not an instance of Map

when i used the sencha touch2.2.1,i met a question. In the viewer:

items: [{
    id: 'mapCanvas',
    xtype:'map',
    useCurrentLocation: true,
}]

In the controller:

var map= Ext.getCmp('mapCanvas');
console.dir(map);
var marker= new google.maps.Marker({
                position: new google.maps.LatLng(25,118),
            });
marker.setMap(map);

report the error:

Uncaught InvalidValueError: setMap: not an instance of Map, and not an instance of StreetViewPanorama

I can see the map,but i can't see the marker, and how to solve the problem?

like image 232
user2996645 Avatar asked Nov 15 '13 14:11

user2996645


3 Answers

Try this:

    marker = new google.maps.Marker({
                position : position,
                setMap : map
            }); 

It worked for me!

like image 194
Chris Avatar answered Oct 14 '22 04:10

Chris


map is not an instance of google map .

var map= Ext.getCmp('mapCanvas').getMap(); // add getMap() here to get the map instance
console.dir(map);
var marker= new google.maps.Marker({
    position: new google.maps.LatLng(25,118),
});
marker.setMap(map);
like image 5
zizoujab Avatar answered Oct 14 '22 02:10

zizoujab


You can add the marker to the map directly by using the marker's setMap() method, as shown in the example below:

var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
var mapOptions = {
  zoom: 4,
  center: myLatlng
}
var map = new google.maps.Map(document.getElementById("map"), mapOptions);

var marker = new google.maps.Marker({
    position: myLatlng,
    title:"Hello World!"
});

// To add the marker to the map, call setMap();
marker.setMap(map);
like image 2
Aman Avatar answered Oct 14 '22 02:10

Aman