这是我关于stackoverflow的第一个问题,所以要温柔:)
我正在使用jQuery,jQuery mobile和jQuery-ui-map插件制作移动Web应用程序。当我刷新应该显示的文件(map.html)时,地图可以很好地工作,但是当从index.html导航时,它根本不会出现。控制台显示没有错误。我试过做$('#map_canvas')。gmap('refresh');在pageinit上,但这也不起作用。当我直接刷新文件时,这也会扰乱平移...
我也尝试过没有页脚菜单中的预取和data-rel =“external”(这搞砸了jquery移动样式)
以下是index.html的页脚导航:
<div data-role="footer" data-theme="a" data-position="fixed">
<div data-role="navbar">
<ul>
<li><a data-transition="fade" class="txt_footer_href_home ui-btn-active" href="index.html" data-prefetch>Home</a></li>
<li><a data-transition="fade" class="txt_footer_href_offers" href="offers.html" data-prefetch>Offers</a></li>
<li><a data-transition="fade" class="txt_footer_href_store" href="store.html" data-prefetch>Store</a></li>
<li><a data-transition="fade" class="txt_footer_href_map" href="map.html" data-prefetch>Map</a></li>
<li><a data-transition="fade" class="txt_footer_href_more" href="more.html" data-prefetch>...</a></li>
</ul>
</div>
</div>
以下是地图的代码:
$('#map_canvas').gmap({'maxZoom':17,'center': new google.maps.LatLng(center_latitude,center_longitude),'callback': function() {
var self = this;
// Get the current position
self.getCurrentPosition(function(position, status) {
// If we got the current position, add the marker
if ( status === 'OK' ) {
// Stor current position in a var
var clientPosition = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
// Add the current position marker
self.addMarker({ id:'mark_pos','position': clientPosition, 'bounds': true})
.click(function() {
$('#map_canvas').gmap('openInfoWindow', { 'content': Lang.mapHtml.txt_marker_my_position_content }, this);
});
// Paint a blue cirecle where your position is
self.addShape('Circle', {
'strokeWeight': 0,
'fillColor': "#008595",
'fillOpacity': 0.25,
'center': clientPosition,
'radius': 15,
'clickable': false
});
// Bind direction marker button and show it
$("#divBtnDirection").show();
var that = this;
$("#btn_directions").click(function() {
that.displayDirections({ 'origin': clientPosition, 'destination':center_latitude+','+center_longitude , 'travelMode': google.maps.DirectionsTravelMode.DRIVING }, { 'panel': document.getElementById('directions') }, function(result, status) {
if ( status === 'OK' ) {
$('#map_canvas').gmap('clear', 'markers');
$("#divBtnDirection").hide();
$("#directions").fadeIn(1000);
}
});
});
}
// Add the shopping centers marker
self.addMarker( { id:'mark_center', 'position': center_latitude+','+center_longitude, 'bounds': true }).click(function() {
$('#map_canvas').gmap('openInfoWindow', { 'content': Lang.mapHtml.txt_marker_center_content }, this);
});
});
}});
该网站目前正在展示here(以挪威语显示)
谢谢!
答案 0 :(得分:0)
首先欢迎来到Stackoverflow .. :) 确保在导航时调用您的函数。尝试将消息框放入函数中并检查。
并尝试在
的head部分调用map功能$(function(){
//your function call
});
希望这会有所帮助..