标签:android javascript jquery google-maps jquery-mobile
如您在图片中所看到的,我在屏幕的左下角有一个放大缩小按钮.我想使其稍微向上移动,或者向其中添加一些新的CSS,以使其易于使用.有人可以帮我解决这个问题吗?
谢谢&问候
.JS
<script type="text/javascript">
/*
* Google Maps documentation: http://code.google.com/apis/maps/documentation/javascript/basics.html
* Geolocation documentation: http://dev.w3.org/geo/api/spec-source.html
*/
$( document ).on( "pageshow", "#map-page", function() {
<?php $coordenadas=explode(',',$fila['Googlemap']);?>
var defaultLatLng = new google.maps.LatLng('<?php echo $coordenadas[0];?>','<?php echo $coordenadas[1];?>');
drawMap(defaultLatLng); // Default to Hollywood, CA when no geolocation support
//var latlng = marker.getPosition();
function drawMap(latlng) {
var myOptions = {
zoom: 10,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map-canvas"), myOptions);
// Add an overlay to the map of current lat/lng
var marker = new google.maps.Marker({
position: latlng,
map: map,
title: "Greetings!"
});
$( window ).resize(function() {
google.maps.event.trigger(map, 'resize');
});
map.setCenter(defaultLatLng);
}
});
</script>
HTML
<div data-shadow="false" data-theme="c" id="map-page" data-role="page">
<div data-role="header" style="background:#006699 !important;color:#fff;">
<a data-rel="back" href="#pageone" class="ui-nodisc-icon ui-new-btn" data-icon="location" data-iconpos="notext" data-corners="true" data-shadow="true" data-iconshadow="true" data-wrapperels="span" data-theme="d" title="Close">Go to Page One</a>
<h1><?php echo $translate->text('Ubicación Aproximada')?> </h1>
<a data-rel="back" href="#pageone" class="ui-nodisc-icon ui-new-btn" data-icon="delete" data-iconpos="notext" data-corners="true" data-shadow="true" data-iconshadow="true" data-wrapperels="span" data-theme="d" title="Close">Back</a>
</div>
<div role="main" class="ui-content" id="map-canvas">
<!-- map loads here... -->
<!---</div> ---->
</div>
</div>
</div>
EDIT1
将以下脚本添加到
$(window).bind( 'orientationchange', function(e){
var ori = window.orientation ;
w = (ori==90 || ori==-90) ? screen.height : screen.width;
h = (ori==90 || ori==-90) ? screen.width : screen.height;
$('#map-canvas').width(w);
$('#map-canvas').height($(window).height()- $('#head1').height());
});
结果变成
回答
这是我的问题的答案,它的工作原理就像移动设备中的Google Map应用程序一样
<script type="text/javascript">
/*
* Google Maps documentation: http://code.google.com/apis/maps/documentation/javascript/basics.html
* Geolocation documentation: http://dev.w3.org/geo/api/spec-source.html
*/
$( document ).on( "pageshow", "#map-page", function() {
<?php $coordenadas=explode(',',$fila['Googlemap']);?>
var defaultLatLng = new google.maps.LatLng('<?php echo $coordenadas[0];?>','<?php echo $coordenadas[1];?>');
$('#map-canvas').height( $(window).height() - $('#head1').height());
drawMap(defaultLatLng); // Default to Hollywood, CA when no geolocation support
//var latlng = marker.getPosition();
function drawMap(latlng) {
var myOptions = {
zoom: 10,
center: latlng,
streetViewControl:true,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map-canvas"), myOptions);
// Add an overlay to the map of current lat/lng
var marker = new google.maps.Marker({
position: latlng,
map: map,
title: "Greetings!"
});
// this is our gem
google.maps.event.addDomListener(window, "resize", function() {
var center = map.getCenter();
google.maps.event.trigger(map, "resize");
map.setCenter(center);
});
}
});
$(window).bind( 'orientationchange', function(e){
var ori = window.orientation ;
w = (ori==90 || ori==-90) ? window.height : window.width;
$('#map-canvas').width(w);
$('#map-canvas').height( $(window).height() - $('#head1').height());
});
</script>
解决方法:
发生这种情况是因为“我的页面”具有标题,并且ID为#map-canvas的div的大小等于窗口的大小.如果没有给出,那么我猜它是默认值.
因此,我提取了标题的大小并将其减去窗口的大小,并将其设置为map-canvas.
像这样
var v = $( window ).height();
h= $('#head1').height();
v = v - h;
$('#map-canvas').height(v);
要么
$('#map-canvas').height( $(window).height() - $('#head1').height());
所以我的完整代码看起来像这样
<script type="text/javascript">
/*
* Google Maps documentation: http://code.google.com/apis/maps/documentation/javascript/basics.html
* Geolocation documentation: http://dev.w3.org/geo/api/spec-source.html
*/
$( document ).on( "pageshow", "#map-page", function() {
<?php $coordenadas=explode(',',$fila['Googlemap']);?>
var defaultLatLng = new google.maps.LatLng('<?php echo $coordenadas[0];?>','<?php echo $coordenadas[1];?>');
var v = $( window ).height();
h= $('#head1').height();
v = v - h;
$('#map-canvas').height(v);
drawMap(defaultLatLng); // Default to Hollywood, CA when no geolocation support
//var latlng = marker.getPosition();
function drawMap(latlng) {
var myOptions = {
zoom: 10,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map-canvas"), myOptions);
// Add an overlay to the map of current lat/lng
var marker = new google.maps.Marker({
position: latlng,
map: map,
title: "Greetings!"
});
$( window ).resize(function() {
google.maps.event.trigger(map, 'resize');
});
map.setCenter(defaultLatLng);
}
});
</script>
标签:android,javascript,jquery,google-maps,jquery-mobile 来源: https://codeday.me/bug/20191011/1894823.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。