javascript - Google Maps wont work under Mobile Mode of Google Chrome
问题描述
The problem is that Google Map does not opening under Google Chrome of Android device (updated to last version).
Under the PC version of Google Chrome it works like a sharm.
The code is a standart map snippet to display a map's marker. So under the mobile Google Chrome I see a blank screen.
But it works when I turn on Google Chrome to the PC mode.
What do I missi to config Google Maps to work under Mobile Mode of Google Chrome?
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
zoom: initialZoom,
center: locCompany,
streetViewControl: false,
mapTypeId: google.maps.MapTypeId.HYBRID,
});
var marker = new google.maps.Marker({
position: locCompany,
map: map,
icon: '@Url.Content("~/Images/logo.png")'
});
map.setZoom(initialZoom);
}
Please, help!
解决方案
Finally I could solve this issue.
I relocated
<script src="https://maps.googleapis.com/maps/api/js?key=MYAPIKEY&callback=initMap"
async defer></script>
into end of body
tag of Layout
page.
And in the map page I put initMap
function into header
like
@section head{
<style>
#map {
height: 70vh !important;
}
</style>
<script>
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
zoom: initialZoom,
center: locCompany,
streetViewControl: false,
mapTypeId: google.maps.MapTypeId.HYBRID,
gestureHandling: 'greedy',
zoomControlOptions: {
style: google.maps.ZoomControlStyle.SMALL,
position: google.maps.ControlPosition.RIGHT_TOP
}
});
var marker = new google.maps.Marker({
position: locCompany,
map: map,
icon: '@Url.Content("~/Images/logo.png")'
});
map.setZoom(initialZoom);
}
</script>
}
推荐阅读
- java - Apache Commons 配置文件位置策略
- scp - 无法 scp AWS Lightsail 实例 - 权限被拒绝
- python-3.x - 在python3中计算日志基数c
- build.gradle - 是否可以使用 Android Studio lint 工具获取详细信息?
- php - 从数据库中仅获取最后 10 个数据,但以相反的方式打印数组
- python - Python创建一个目录并将.txt文件保存到其中
- c# - 非管理员时 HttpClient 错误“请求被中止:无法创建 SSL/TLS 安全通道”
- regex - 如何匹配更改的标题下的一组文本
- javascript - Angular 服务器端渲染模板 (.cshtml) 使用转义符号解析错误
- jetty - 找不到适用于 Java 版本的匹配 alpn-boot JAR:12.0.2