Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $('document').ready(function(){
- $('#geobutton').click(determineLocation);
- $('#showwaybutton').click(letsGo);
- });
- var address1;
- var address2;
- var map;
- function initialize() {
- var myOptions = {
- zoom: 12,
- center: new google.maps.LatLng(49.844808, 8.858109),
- mapTypeId: google.maps.MapTypeId.ROADMAP,
- mapTypeControl: true,
- scaleControl: false,
- navigationControl: true,
- navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
- streetViewControl: false
- };
- map = new google.maps.Map(document.getElementById("map-canvas"), myOptions);
- }
- google.maps.event.addDomListener(window, "load", initialize);
- function letsGo() {
- address1 = document.getElementById("address1").value;
- address2 = "Fasanenhof Habitzheim 9, 64853 Otzberg";
- showMap();
- }
- function showMap() {
- var mapOptions = {
- zoom: 12,
- center: new google.maps.LatLng(49.844808, 8.858109),
- mapTypeId: google.maps.MapTypeId.ROADMAP,
- mapTypeControl: true,
- scaleControl: false,
- navigationControl: true,
- navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
- streetViewControl: false
- };
- map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
- // show route between the points
- directionsService = new google.maps.DirectionsService();
- directionsDisplay = new google.maps.DirectionsRenderer();
- directionsDisplay.setMap(map);
- var request = {
- origin:address1,
- destination:address2,
- travelMode: google.maps.DirectionsTravelMode.DRIVING
- };
- directionsDisplay.setPanel(document.getElementById("map-directions"));
- directionsService.route(request, function(result, status) {
- if (status != google.maps.DirectionsStatus.OK) {
- alert('Directions failed: ' + status);
- return;
- } else {
- directionsDisplay.setDirections(result);
- }
- });
- }
- function determineLocation() {
- var directionsService = new google.maps.DirectionsService(),
- directionsDisplay = new google.maps.DirectionsRenderer(),
- createMapy = function (start) {
- var myOptions = {
- zoom: 12,
- center: new google.maps.LatLng(49.844808, 8.858109),
- mapTypeId: google.maps.MapTypeId.ROADMAP,
- mapTypeControl: true,
- scaleControl: false,
- navigationControl: true,
- navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
- streetViewControl: false
- };
- map = new google.maps.Map(document.getElementById("map-canvas"), myOptions);
- };
- createMap = function (start) {
- var travel = {
- origin : (start.coords)? new google.maps.LatLng(start.lat, start.lng) : start.address,
- destination : "Fasanenhof Habitzheim 9, 64853 Otzberg",
- travelMode : google.maps.DirectionsTravelMode.DRIVING
- },
- mapOptions = {
- zoom: 12,
- center: new google.maps.LatLng(49.844808, 8.858109),
- mapTypeId: google.maps.MapTypeId.ROADMAP,
- mapTypeControl: true,
- scaleControl: false,
- navigationControl: true,
- navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
- streetViewControl: false
- };
- map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
- directionsDisplay.setMap(map);
- directionsDisplay.setPanel(document.getElementById("map-directions"));
- directionsService.route(travel, function(result, status) {
- if (status != google.maps.DirectionsStatus.OK) {
- alert('Directions failed: ' + status);
- return;
- } else {
- 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:
- createMapy();
- });
- } else if (google.gears) {
- // Try Google Gears Geolocation
- } else {
- // No geolocation fallback:
- createMapy();
- }
- }
Add Comment
Please, Sign In to add comment