Sencha地图上的Sencha Touch 2多个纬度和经度

时间:2022-04-11 18:54:45

I am building an app which contains a list of addresses. This app is working in such a way that once the user clicks on each of the items (addresses) in the list, the next page shows a map, and the map has a marker which points to the exact location of the address clicked on. This is made possible due to the Latitude and Longitude coordinates stated in code. My problem is that I have more than one address, and each of these addresses have a unique longitude and latitude. I want to make my app work in such a way that when a user clicks on any address they are interested in, the app will open a page and show the map and a marker pointing to the exact location of the address on the map. My code's below: it is working perfectly, BUT when the user clicks on the address, it takes them to the same logitude and latitude.

我正在构建一个包含地址列表的应用程序。这个应用程序的工作方式是,一旦用户点击列表中的每个项目(地址),下一页显示一个地图,地图上有一个标记,指向所点击地址的确切位置。由于代码中规定的纬度和经度坐标,因此可以实现这一点。我的问题是我有多个地址,每个地址都有一个独特的经度和纬度。我想让我的应用程序以这样的方式工作:当用户点击他们感兴趣的任何地址时,应用程序将打开一个页面并显示地图和指向地图上地址的确切位置的标记。我的代码如下:它工作正常,但当用户点击地址时,它会将它们带到相同的逻辑和纬度。

My store:

Ext.define('List.store.Presidents', {
extend : 'Ext.data.Store',

config : {
    model : 'List.model.President',
    sorters : 'lastName',
    grouper : function(record) {
        return record.get('lastName')[0];
    },

    data : [{

        firstName : "Ikhlas HQ",
        lastName : "Tower 11A, Avenue 5, Bangsar South, No.8 Jalan Kerinchi 59200 Kuala Lumpur",
        latitude : 3.110649,
        longitude : 101.664991,
        id: 'm12',
    },
    {
        firstName : "PEJABAT WILAYAH SELANGOR",
        lastName : "No. 97, 97-1 & 97-2, Jalan Mahogani 5/KS7, Ambang Botanic, 41200 Klang,   Selangor",
        latitude : 3.003384,
        longitude : 101.45256,
        id: 'm1',
    }, ]

}
});

My controller:

Ext.define('List.controller.Main', {
extend: 'Ext.app.Controller',

config: {

    control: {
        'presidentlist': {
            disclose: 'showDetail'
        },
     }
 },
showDetail: function(list, record) {
            this.getMain().push({
                xtype: 'presidentdetail',
                title: record.fullName(),

listeners: {
            maprender: function(comp, map) {
                var position = new google.maps.LatLng(5.978132,116.072617);
                var marker = new google.maps.Marker({
                    position: position,
                    map: map
                        });
            google.maps.event.addListener(marker, 'click', function() {
                    infowindow.open(map, marker);
                        });
            setTimeout(function() {
                    map.panTo(position);
                }, 1000);

                },
           }, 
        })
     },
});

My view:

Ext.define('List.view.PresidentDetail', {
extend : 'Ext.Map',
xtype: 'presidentdetail',

    config: {
                title: 'Details',
                styleHtmlContent: true,
                scrollable: 'vertical',
                //useCurrentLocation: true,
                layout: 'fit',

    mapOptions: {
                zoom: 16,
                mapTypeId: google.maps.MapTypeId.ROADMAP,
                navigationControl: true,
                navigationControlOptions: {
                style: google.maps.NavigationControlStyle.DEFAULT
                 }
            },
    }


});

My model:

Ext.define('List.model.President', {
extend : 'Ext.data.Model',
config : {
    fields : ['firstName', 'middleInitial', 'lastName', 'latitude', 'longitude']
},
fullName : function() {
    var d = this.data, names = [d.firstName, (!d.middleInitial ? "" : d.middleInitial + "."), d.lastName];
    return names.join(" ");
}
});

Help me out please. I need each of the addresses on the list to be tagged with a latitude and longitude so that when the user clicks on the address, it will point to the exact location the map.

请帮帮我。我需要使用纬度和经度标记列表中的每个地址,以便当用户点击地址时,它将指向地图的确切位置。

1 个解决方案

#1


0  

Take a look at the kentuni app on GitHub. It is in sencha touch v1 and uses leaflet but it should be a good reference - it does exactly what you want with a list of locations that when clicked pushes a map view with marker.

看看GitHub上的kentuni应用程序。它是在sencha touch v1并使用传单,但它应该是一个很好的参考 - 它完全符合你想要的位置列表,点击时用标记推送地图视图。

#1


0  

Take a look at the kentuni app on GitHub. It is in sencha touch v1 and uses leaflet but it should be a good reference - it does exactly what you want with a list of locations that when clicked pushes a map view with marker.

看看GitHub上的kentuni应用程序。它是在sencha touch v1并使用传单,但它应该是一个很好的参考 - 它完全符合你想要的位置列表,点击时用标记推送地图视图。