![](/img/trans.png)
[英]Google Maps Issue Cannot call method 'apply' of undefined?
[英]Cannot call method 'apply' of undefined on setting directions for jquery google maps plugin
我已經按照創建jQuery Mobile的谷歌地圖畫布教程這里 ,並試圖設置了但是我在我的JavaScript控制台收到此錯誤:
未捕獲的TypeError:無法調用未定義的方法'apply'
我想我可能在某處丟失了回調,但是我無法發現它,有人可以給我一個指針嗎?
這是我在頁面顯示時初始化和顯示地圖的方式,這可以正常工作我可以在地圖上平移/縮放:
$('#map_canvas').gmap({ 'center': latLon,'scrollwheel':false});
$('#map_canvas').gmap('option', 'zoom', 12);
$('#map_canvas').gmap().bind('pageshow', function(ev, map){
$('#map_canvas').gmap('addMarker', {'position':latLon, 'bounds':false}).click(function(){
$('#map_canvas').gmap('openInfoWindow', {'content':myAddress}, this);
});
});
我的HTML頁面上有這些字段:
<p>
<label for="from">From</label>
<input id="from" class="ui-bar-c" type="text" value="Los Angeles" />
</p>
<p>
<label for="to">To</label>
<input id="to" class="ui-bar-c" type="text" value="New York" />
</p>
<a id="submit" href="#" data-role="button" data-icon="search">Get directions</a>
<div id="map_canvas" style="width:100%;height:300px"></div>
<div id="results" class="ui-listview ui-listview-inset ui-corner-all ui-shadow" style="display:none;">
<div class="ui-li ui-li-divider ui-btn ui-bar-b ui-corner-top ui-btn-up-undefined">Results</div>
<div id="directions"></div>
<div class="ui-li ui-li-divider ui-btn ui-bar-b ui-corner-bottom ui-btn-up-undefined"></div>
</div>
onclick綁定到這個JS函數:
function getDirections()
{
$('#map_canvas').gmap('displayDirections', { 'origin': 'Los Angeles, USA', 'destination': 'New York, USA', 'travelMode': google.maps.DirectionsTravelMode.DRIVING }, { 'panel': document.getElementById('panel') }, function(result, status) {
if ( status === 'OK' ) {
alert('Results found!');
}
});
}
事實證明這是因為不包括庫。 在我下載的文件中,有一個jquery.ui.map.services.js文件必須在它工作之前包含。 這就是方向功能所在的地方。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.