Uncaught InvalidValueError: setMap: not an instance of Map

前端 未结 7 1053
萌比男神i
萌比男神i 2021-02-19 12:23

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

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


        
相关标签:
7条回答
  • 2021-02-19 12:51

    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');
    
    0 讨论(0)
  • 2021-02-19 12:57

    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
        });
    
    0 讨论(0)
  • 2021-02-19 12:59

    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());
    
    0 讨论(0)
  • 2021-02-19 13:04

    Try this:

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

    It worked for me!

    0 讨论(0)
  • 2021-02-19 13:04

    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

    0 讨论(0)
  • 2021-02-19 13:08

    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);
    
    0 讨论(0)
提交回复
热议问题