I’m attempting to move a large block of Google Maps API script off of the page and into an included .js file.
But! In order to do that I’ve got to tweak the function to accept passed variables.
Here’s the start of the script normally…
<script type="text/javascript">
//<![CDATA[
function loadGmap() {
var map1options = {
center: new google.maps.LatLng(-12.043333,-77.028333),
mapTypeId: google.maps.MapTypeId.TERRAIN,
zoom: 4,
minZoom: 2,
streetViewControl: false
};
and here’s me try to pass the first variable (and failing)…
<script type="text/javascript">
//<![CDATA[
function loadGmaps() {
loadGmap('-12.043333,-77.028333');
}
function loadGmap(coordinates) {
var map1options = {
center: new google.maps.LatLng(coordinates),
mapTypeId: google.maps.MapTypeId.TERRAIN,
zoom: 4,
minZoom: 2,
streetViewControl: false
};
Ideas? Maybe this shouldn’t be a string… or something?
There you pass two arguments to
LatLng. In your new function, you still need to pass two arguments toLatLng. The easiest way to do this is to accept two arguments to your function: