Google maps API required

旧时模样 提交于 2019-12-11 07:51:51

问题


When i try to show the map in my aplication its showing the messsage as "Google maps API required" in the view, Here my code

   var mapapnel = Ext.create('Ext.Panel', {
                      id: 'mapapnel',
                      height: '100%',
                      width: '100%',
                      fullscreen: true,
                      layout:'fit',
                      layout:'vbox',
                      items: [{
                      xtype: 'toolbar',
                      ui:'light',
                      docked: 'top',
                      title: 'Find location',
                      items: [{
                               text: 'Back',
                               ui: 'back',
                               handler: function() {
                                         Ext.getCmp('homepnl').setActiveItem(1);
                                                   }
                                },{
                                   xtype:'spacer'
                                  }]},
                                 {
                                  xtype:'map',
                                  useCurrentLocation:true
                                 }]});

What change required to show the map?please help me to solve


回答1:


You need to load the google maps javascript api.

you can do this by adding the code in your index.html file.

<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=true"></script> 



回答2:


Two things

1) The panel which contains map should be card layout.

2) Without setting center mapOptions, map not showing.

Give Lat & Lng value as you need.

var mapapnel = Ext.create('Ext.Panel', {
          id: 'mapapnel',
          layout:'card',
          items: [{
              xtype: 'toolbar',
              ui:'light',
              docked: 'top',
              title: 'Find location',
              items: [{
                  text: 'Back',
                  ui: 'back',
                  handler: function() {
                     Ext.getCmp('homepnl').setActiveItem(1);
                  }
              }
            ]},
            {
             xtype:'map',
             useCurrentLocation:true,
             mapOptions: {
              zoom: 12,
              zoomControl : true,
              center: new google.maps.LatLng(Lat, Lng),
              disableDefaultUI: true
           }]
});


来源:https://stackoverflow.com/questions/18874379/google-maps-api-required

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!