Reputation: 2789
I'm trying to figure out why this PHP script isn't creating the map I specify in the HTML. any ideas?
<!doctype html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style>
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map { height: 100% }
</style>
<script
src="http://maps.googleapis.com/maps/api/js?sensor=false">
</script>
<?php
$lat = $_POST['lat'];
$long = $_POST['long'];
echo "
<script>
function callMap() {
var latlng = new google.maps.LatLng($lat, $long);"; ?>
var options = {
zoom: 5,
center: latlng,
mapTypeId = google.maps.MapTypeId.TERRAIN
};
var map = new google.maps.Map(document.getElementById("map"),
options);
}
</script>
</head>
<body onload="callMap()">
<div id="map"></div>
</body>
</html>
Upvotes: 0
Views: 125
Reputation: 2052
Your options
declaration syntax is messed up:
var options = {
zoom: 5,
center: latlng,
mapTypeId = google.maps.MapTypeId.TERRAIN // ERROR
};
Should be
var options = {
zoom: 5,
center: latlng,
mapTypeId: google.maps.MapTypeId.TERRAIN
};
Upvotes: 3
Reputation: 31912
I don't use PHP so I can't tell if there's anything wrong with that code. If you removed the PHP and hardcoded lat/lon values, does the map work? Maybe one problem could be just what values the form is posting with the latitude and longitude. You're not doing any sort of validation to ensure they are within acceptable bounds, e.g. +90 to -90 for latitude and +180 to -180 for longitude.
Upvotes: -1