向 Sencha Touch 谷歌地圖添加標記 (Adding Marker to Sencha Touch Google Maps)


問題描述

向 Sencha Touch 谷歌地圖添加標記 (Adding Marker to Sencha Touch Google Maps)

Hi I am trying to add a marker to sencha touch v.2.2.1 google maps. I can see the map, but not the marker. I also added the required lib: <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>

config: {
    items: [{
        xtype: 'map',
        itemId: 'mapHomeView',
        width: Ext.os.deviceType == 'Phone' ? null : 1500,
        height: Ext.os.deviceType == 'Phone' ? null : 350,
        useCurrentLocation: true,
        listeners: {
        maprender: function(extMapComponent, googleMapComp){
            var marker = new google.maps.Marker({
                title: 'test',
                position: new google.maps.LatLng (49.279989, ‑123.126333),
                map: Ext.ComponentQuery.query('#mapHomeView')[0].map,
                // map: googleMapComp,
            });

            marker.setMap(Ext.ComponentQuery.query('#mapHomeView')[0].map);
        }
    }]
}

I am using google chrome, for testing the app. I enabled the location requests in the settings.

Neither the line map: ... nor the commented map: ... line is working.


參考解法

方法 1:

This solved my problem. I found it in the examples of sencha touch:

config: {
    control: {
        'map[itemId="mapHomeView"]': {
            maprender: 'mapHomeViewMapRenderer'
        }
    }
},

mapHomeViewMapRenderer: function(comp, map) {
    var map = Ext.ComponentQuery.query('#mapHomeView')[0].getMap();

    var image = new google.maps.MarkerImage(
        'resources/images/point.png',
        new google.maps.Size(32, 31),
        new google.maps.Point(0, 0),
        new google.maps.Point(16, 31)
    );

    var shadow = new google.maps.MarkerImage(
        'resources/images/shadow.png',
        new google.maps.Size(64, 52),
        new google.maps.Point(0, 0),
        new google.maps.Point(‑5, 42)
    );

    var position = new google.maps.LatLng(49.279989, ‑123.126333);

    var marker = new google.maps.Marker({
        position: position,
        title: 'test',
        shadow: shadow,
        icon: image,
        map: map
    });
},

(by NiklasNiklas)

參考文件

  1. Adding Marker to Sencha Touch Google Maps (CC BY‑SA 3.0/4.0)

#google-chrome #javascript #sencha-touch #google-maps






相關問題

chrome 可以播放 html5 mp4 視頻但 html5test 說 chrome 不支持 mp4 視頻編解碼器 (chrome could play html5 mp4 video but html5test said chrome did not support mp4 video codec)

向 Sencha Touch 谷歌地圖添加標記 (Adding Marker to Sencha Touch Google Maps)

Mathjax 方程在每個公式上都有符號 `|` (Mathjax equation got sign `|` on every formula)

Google Chrome 中 zip 文件的 Mime 類型 (Mime type for zip file in Google Chrome)

Chrome 擴展:popup.html 通過 contentscript.js 動態創建 (Chrome Extension: popup.html dynamically create via contentscript.js)

CSS 3漸變不適用於chrome / firefox (CSS 3 gradient not working on chrome/firefox)

如何訪問網頁 DOM 而不是擴展頁面 DOM? (How to access the webpage DOM rather than the extension page DOM?)

覆蓋 navigator.bluetooth.requestDevice() 的默認行為 (Override default behavior of navigator.bluetooth.requestDevice())

VBA Selenium Chrome:如何更改鏈接 (VBA Selenium Chrome : How to Change Link)

鼠標懸停在 Chrome 瀏覽器上的日期和時間選擇器圖標上時的光標指針 (Cursor pointer when mouse-over on date and time picker icon on chrome browser)

更改 HTML 選擇箭頭背景顏色 (Change HTML Select arrow background color)

旋轉的圖像無法在 Google Chrome 瀏覽器中正確顯示 (Rotated images not displaying correctly in Google Chrome browser)







留言討論