user2996645
user2996645

Reputation: 131

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?

Upvotes: 13

Views: 49757

Answers (7)

Aman
Aman

Reputation: 640

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);

Upvotes: 2

zizoujab
zizoujab

Reputation: 7800

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);

Upvotes: 5

Elias
Elias

Reputation: 11

var map is a HTML element you need an instance of the google.maps.Map Object

var map = google.maps.Map(document.querySelector("#mapCanvas"),{
      center: new google.maps.LatLng(24.027872, -104.655278),
      zoom: 12
    });

then....

var marker= new google.maps.Marker({
  position: new google.maps.LatLng(25,118),
  map: map
    });

Upvotes: 1

koti bajjuri
koti bajjuri

Reputation: 81

mapCanvas is Ext map component which holds the map instance.

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

Upvotes: 0

Chris
Chris

Reputation: 185

Try this:

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

It worked for me!

Upvotes: 18

Anand Gupta
Anand Gupta

Reputation: 5700

Try this:

var  latlngbounds = new google.maps.LatLngBounds(),
     position = new google.maps.LatLng(25,118),
     marker = new google.maps.Marker({
            position : position,
            map : map
        }); 

latlngbounds.extend(position);

map.fitBounds(latlngbounds);

Here map is the rendered google.map.Map instance

Upvotes: 0

geocodezip
geocodezip

Reputation: 161334

The marker.setMap method expects the argument to be a google.maps.Map object. This is not one of those:

var map= Ext.getCmp('mapCanvas');

Upvotes: 0

Related Questions