3

Im trying to place a google map on my website but its not working. Here is the code that I have. Can anyone tell me what Im 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> 

6 Answers 6

3

You have wrong formatting and possibly bad parameters:

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

should be something like:

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

making sure the MY_API_KEY is replaced by your Google Map API key, or simply ignore this parameter if you don't need it. Not sure you want the sensor to TRUE, I just guessed since you had an orphan =TRUE parameter

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much. I can't believe I didn't realize this silly mistake. Thanks again :)
2

Your script line should be

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

Also california is not a valid center, you need a latLng like:

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

Comments

2

Wrong

<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> 

Comments

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

That's not right at all

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

would be closer, if that's the problem

Comments

0

yes the script tag needs to be

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

and set sensor=false

Comments

0

By the way, the parameter sensor in the Url has to be set to true or false depending on the app. If the the app uses a sensor like a gps transmitter to find out the user-location, it is true. More info here

The key as a parameter is only necessary if the website/app has no Google oauth access token yet and will not lead to any verification of the user as opposed to the oauth token .

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.