Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
122
rated 0 times [  124] [ 2]  / answers: 1 / hits: 27358  / 11 Years ago, fri, march 29, 2013, 12:00:00

I've been trying to embed a google map in my site , but with not much success.
I've used the next code section: (i'm using an actual api key on my own computer)



<script type=text/javascript
src=https://maps.googleapis.com/maps/api/js?key=myapikey&sensor=true>
</script>
<script type=text/javascript>
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(-34.397, 150.644),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById(map-canvas),
mapOptions);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>


inside <body> section i've added <div id=map-canvas style=width: 40%; height: 40%></div>



How could I handle this problem ?
Thanks in advance


More From » html

 Answers
16

Specify the canvas' width and height as absolute lengths rather than %.



For example :



<div id=map-canvas style=width: 300px; height: 400px></div>


Alternatively, stick with % for the canvas but put it inside a container with width and height specified as absolute lengths.



<div style=width:1000px; height:800px;>
<div id=map-canvas style=width: 40%; height: 40%></div>
</div>

[#79246] Thursday, March 28, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
devlin

Total Points: 474
Total Questions: 113
Total Answers: 100

Location: Sweden
Member since Fri, Apr 16, 2021
3 Years ago
devlin questions
Tue, Apr 27, 21, 00:00, 3 Years ago
Sat, Oct 31, 20, 00:00, 4 Years ago
Fri, Aug 28, 20, 00:00, 4 Years ago
;