单击地图时如何获取点的经度和纬度

时间:2019-05-09 21:55:55

标签: extjs click

gmappanel组件中单击地图时如何获取点的经纬度?

Ext.require('Ext.ux.GMapPanel');
var map = Ext.create('Ext.panel.Panel', {
    layout: 'fit',
    header: false,
    border: false,
    itemId:'map',
    style: 'padding: 0; border-width: 0;',
    draggable: false,
    height:290,
    width:350,
    items: [{
        xtype: 'gmappanel',
        useCurrentLocation :true,
        center:
        {
            lat:36,
            lng:36
        },
        mapOptions: {
            mapTypeId: google.maps.MapTypeId.ROADMAP,
            zoom: 6
        }
    }]
});
component.add(map);

2 个答案:

答案 0 :(得分:1)

呈现google map之后,您需要向map对象添加侦听器。

var map = Ext.create('Ext.panel.Panel', {
    layout: 'fit',
    header: false,
    border: false,
    itemId: 'map',
    style: 'padding: 0; border-width: 0;',
    draggable: false,
    height: 290,
    width: 350,
    items: [{
        xtype: 'gmappanel',

        useCurrentLocation: true,
        center: {
            lat: 36,
            lng: 36
        },
        mapOptions: {
            mapTypeId: google.maps.MapTypeId.ROADMAP,
            zoom: 6
        },
        listeners: {
            mapready: function () {
                google.maps.event.addListener(this.gmap, "click", function (e) {
                    var latLng = e.latLng;
                    alert(Ext.String.format("Position: {0}}", e.latLng))
                });
            }
        }
    }]
});

答案 1 :(得分:1)

在地图上添加“点击”监听器

google.maps.event.addListener(myMap, 'click', function (event) {
       var latitude= event.latLng.lat();
       var longitude= event.latLng.lng();
     });