Google map not showing

I am trying to place a Google map on my website but it doesn’t work. Here is the code I have. Can someone tell me what I'm doing wrong. Thanks

<head>
<title>Environment Impact</title>
<link rel="stylesheet" href="style.css" type="text/css">
<script>src="http://maps.googleapis.com/maps/api/js?key=MY_API_KEY=TRUE"></script>


 <script type="text/javascript">
  function initialize() {
          var california = new google.maps.LatLng(-122.23354, 37.48787);
          var myOptions = {
            center: california,
            zoom: 8,
            mapTypeId: google.maps.MapTypeId.ROADMAP
          };
          var map = new google.maps.Map(document.getElementById("map-canvas"), myOptions);
        }
</script>
 </head>
 <body onload="initialize()">
    <div id="map-canvas" style="width:800px; height:600px; border:1px solid #000;"></div>
 </body>
+3
source share
6 answers

You have the wrong formatting and possibly bad options:

<script>src="http://maps.googleapis.com/maps/api/js?key=MY_API_KEY=TRUE"></script>

should look something like this:

<script src="http://maps.googleapis.com/maps/api/js?key=MY_API_KEY&sensor=TRUE"></script>

make sure to MY_API_KEYreplace it with your Google Map API key or just ignore this option if you don't need it. Not sure what you want sensorup to TRUE, I just guessed since you had the orphan option=TRUE

+2
source

Your script line should be

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>

Also californianot a valid center, you need latLng like:

center: new google.maps.LatLng(37.19533058280067, -120.234375),

+2

<script>src="http://maps.googleapis.com/maps/api/js?key=MY_API_KEY=TRUE"></script>

Right

<script src="http://maps.googleapis.com/maps/api/js?key=MY_API_KEY&sensor=true"></script>
+2
<script>src="http://maps.googleapis.com/maps/api/js?key=MY_API_KEY=TRUE"></script>

.

<script src="http://maps.googleapis.com/maps/api/js?key=MY_API_KEY&sensor=false"></script>

,

+1

script

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>

= false

0

By the way, the parameter sensorin Url should be set to true or false depending on the application. If the application uses the sensor as a gps transmitter to find out the user's location, this true. More here

The key as a parameter is necessary only if the website / application does not have a Google oauth access token and does not lead to user verification, unlike the oauth token.

0
source

All Articles