Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-04-2012, 01:52 AM   PM User | #1
Snoowpy
New to the CF scene

 
Join Date: Nov 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Snoowpy is an unknown quantity at this point
Google maps API dropdownbox question

Hey, a codingnoob here.

I have to make an app for a schoolproject and I'm a total javascript beginner.
I have been messing around with a sample code, but I need to add a dropdownbox to the code.

Point A has to be a Geolocation and Point B has to be the location of the dropdown box. Now I've looked at sample codes and have a general idea but I can not for the life of me get it to work correctly, I'm hoping one of you fine gentleman can help me out... it should be simple but I cant get it to work.

Code:
(function () {
						var directionsService = new google.maps.DirectionsService(),
							directionsDisplay = new google.maps.DirectionsRenderer(),
							createMap = function (start) {
								var travel = {
										origin : (start.coords)? new google.maps.LatLng(start.lat, start.lng) : start.address,
										destination : "Fahrenheitstraat, The Netherlands",
										travelMode : google.maps.DirectionsTravelMode.DRIVING
										// Exchanging DRIVING to WALKING above can prove quite amusing :-)
									},
									mapOptions = {
										zoom: 10,
										// Default view: downtown Stockholm
										center : new google.maps.LatLng(52.0758733, 4.2721553),
										mapTypeId: google.maps.MapTypeId.ROADMAP
									};

								map = new google.maps.Map(document.getElementById("map"), mapOptions);
								directionsDisplay.setMap(map);
								directionsDisplay.setPanel(document.getElementById("map-directions"));
								directionsService.route(travel, function(result, status) {
									if (status === google.maps.DirectionsStatus.OK) {
										directionsDisplay.setDirections(result);
									}
								});
							};

							// Check for geolocation support	
							if (navigator.geolocation) {
								navigator.geolocation.getCurrentPosition(function (position) {
										// Success!
										createMap({
											coords : true,
											lat : position.coords.latitude,
											lng : position.coords.longitude
										});
									}, 
									function () {
										// Gelocation fallback: Defaults to Stockholm, Sweden
										createMap({
											coords : false,
											address : "Den Haag, Nederland"
										});
									}
								);
							}
							else {
								// No geolocation fallback: Defaults to Lisbon, Portugal
								createMap({
									coords : false,
									address : "Lisbon, Portugal"
								});
							}
					})();

Normally I like to figure out things myself but the deadline is coming up and I'm tired and having problems at home so I'm not sure how much time i've got left.

I tried doing something like this:
Code:
function calcRoute() {
    var start = (start.coords)? new google.maps.LatLng(start.lat, start.lng) : start.address,;
    var end = document.getElementById("end").value;
    var distanceInput = document.getElementById("distance");
but to no avail
Snoowpy is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:29 PM.


Advertisement
Log in to turn off these ads.