JavaScript-如何使Google Map像Android手机中的Google Map应用程序一样工作
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了JavaScript-如何使Google Map像Android手机中的Google Map应用程序一样工作,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含5238字,纯文字阅读大概需要8分钟。
内容图文
如您在图片中所看到的,我在屏幕的左下角有一个放大缩小按钮.我想使其稍微向上移动,或者向其中添加一些新的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>
内容总结
以上是互联网集市为您收集整理的JavaScript-如何使Google Map像Android手机中的Google Map应用程序一样工作全部内容,希望文章能够帮你解决JavaScript-如何使Google Map像Android手机中的Google Map应用程序一样工作所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。