I'm currently working on a school project that involves coding. I've successfully implemented geolocation code to display the user's location upon page load. Now, I need to add a drop-down box that allows users to select from three additional locations - Walt Disney World, Honolulu, and Paris. To achieve this, I believe I need to use if statements in conjunction with Google Maps API for each location to change the map image displayed based on the selection made by the user. Below is a snippet of my current code:
CSS
html{
height: 90%
}
body{
height: 100%;
margin: 0px;
padding: 0px;
}
#map_canvas{
height: 90%;
width: 90%;
}
JS
var watchID;
var geo; // for the geolocation object
var map; // for the google map object
var mapMarker; // the google map marker object
// position options
var MAXIMUM_AGE = 200; // miliseconds
var TIMEOUT = 300000;
var HIGHACCURACY = true;
function getGeoLocation() {
try {
if (!!navigator.geolocation) return navigator.geolocation;
else return undefined;
} catch (e) {
return undefined;
}
}
// More JavaScript functions...
window.onload = function() {
if ((geo = getGeoLocation())) {
startWatching();
} else {
alert('Geolocation not supported.')
}
}
HTML
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
<div id="map_canvas"></div>
<section>
<div id="vacationLocations">
<h2>Vacation Locations</h2>
<form name="tripSelection" method="post" method="get">
<div class="formRow">
<label for="serviceSelection">
Trip Selection</label>
<select name="tripSelection" id="tripSelection" class="validated" required>
<option value="">-Select One-</option>
<option value="1">Paris, France</option>
<option value="2">Honolulu, Hawaii</option>
<option value="3">Walt Disney World, Florida</option>
</select>
</div>
</div>
This is what I have already in the program and it is working. Here is the code I have for Disney followed by the coordinates I have found for the other locations:
<!DOCTYPE html>
<html>
<head>
<script
src="http://maps.googleapis.com/maps/api/js">
</script>
<script>
function initialize() {
var mapProp = {
center:new google.maps.LatLng(28.3341439,-81.5871676),
zoom:14,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
var map=new google.maps.Map(document.getElementById("googleMap"), mapProp);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
Coordinates: - Paris, France: 48.8589507,2.2775174 - Honolulu, Hawaii: 21.3282956,-157.9390673
Any assistance on how to implement changing the map based on the selected location would be highly appreciated.