admin管理员组文章数量:1432446
I'm currently working on an IP tracking program, but I have some problems with the google maps function, I can't get the map to show or put a marker on the IP location. Can anyone point me in the right directions?
Here is the code I've used for the map, I took it from googles own website.
<div id="map"></div>
<script>
var map;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -34.397, lng: 150.644},
zoom: 8
});
}
</script>
<script src=";callback=initMap"
async defer></script>
Here's my plete code:
I'm currently working on an IP tracking program, but I have some problems with the google maps function, I can't get the map to show or put a marker on the IP location. Can anyone point me in the right directions?
Here is the code I've used for the map, I took it from googles own website.
<div id="map"></div>
<script>
var map;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -34.397, lng: 150.644},
zoom: 8
});
}
</script>
<script src="https://maps.googleapis./maps/api/js?key=AIzaSyAnoX8LSgSg5-pRiF5_IzZ313VsNZzuo-4&callback=initMap"
async defer></script>
Here's my plete code:
Share Improve this question edited Feb 6, 2019 at 8:06 Adam asked Feb 6, 2019 at 7:42 AdamAdam 471 silver badge5 bronze badges 1- 1 Please go read How to Ask and minimal reproducible example. Code relevant to your problem belongs directly into your question (in text form & properly formatted), not just on an external site. Please edit accordingly. – 04FS Commented Feb 6, 2019 at 8:01
3 Answers
Reset to default 11To show map you need to provide height
.
Add this height in your style for div with id map
#map {
height: 300px;
}
Update:
if map container (with id map) should take up 100% of the height of the HTML body. Note that we must specifically declare those percentages for and as well.
#map {
height: 100%;
}
html, body {
height: 100%;
margin: 0;
padding: 0;
}
In my case, div was like
<div id="map" style="height: 100%; width: 100%"></div>
but map appeared only when I've add position: absolute property explicitly. So, the result was
<div id="map" style="height: 100%; width: 100%; position: absolute"></div>
and it works.
You didn't added the api key
Google Maps JavaScript API warning: NoApiKeys https://developers.google./maps/documentation/javascript/error-messages#no-api-keys mw.m @ util.js:220 util.js:220 Google Maps JavaScript API warning: InvalidKey https://developers.google./maps/documentation/javascript/error-messages#invalid-key
本文标签: javascriptGoogle maps not showingHTMLStack Overflow
版权声明:本文标题:javascript - Google maps not showing, HTML - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1740291000a2255690.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论