daily pastebin goal
3%
SHARE
TWEET

Untitled

a guest Mar 13th, 2018 216 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDHIP7rWh6XQFCO_dPIVnW3TXMZ4fiRtSY" type="text/javascript"></script>
  2. <script type="text/javascript">
  3.     //<![CDATA[
  4.     var map;
  5.     var markers = [];
  6.     var infoWindow;
  7.     var locationSelect;
  8.  
  9.     function load() {
  10.         map = new google.maps.Map( document.getElementById( "map" ), {
  11.             center: new google.maps.LatLng( 54, -2 ),
  12.             zoom: 6,
  13.             mapTypeId: 'terrain',
  14.             mapTypeControlOptions: {
  15.                 style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
  16.             }
  17.         } );
  18.         infoWindow = new google.maps.InfoWindow();
  19.  
  20.         locationSelect = document.getElementById( "locationSelect" );
  21.         locationSelect.onchange = function () {
  22.             var markerNum = locationSelect.options[ locationSelect.selectedIndex ].value;
  23.             if ( markerNum != "none" ) {
  24.                 google.maps.event.trigger( markers[ markerNum ], 'click' );
  25.             }
  26.         };
  27.     }
  28.  
  29.     function searchLocations() {
  30.         var address = document.getElementById( "addressInput" ).value;
  31.         var geocoder = new google.maps.Geocoder();
  32.         geocoder.geocode( {
  33.             address: address, 'componentRestrictions':{'country':'GB'}
  34.         }, function ( results, status ) {
  35.             if ( status == google.maps.GeocoderStatus.OK ) {
  36.                 searchLocationsNear( results[ 0 ].geometry.location );
  37.             } else {
  38.                 alert( address + ' not found' );
  39.             }
  40.         } );
  41.     }
  42.  
  43.     function clearLocations() {
  44.         infoWindow.close();
  45.         for ( var i = 0; i < markers.length; i++ ) {
  46.             markers[ i ].setMap( null );
  47.         }
  48.         markers.length = 0;
  49.  
  50.         locationSelect.innerHTML = "";
  51.         var option = document.createElement( "option" );
  52.         option.value = "none";
  53.         option.innerHTML = "See all results:";
  54.         locationSelect.appendChild( option );
  55.     }
  56.  
  57.     function searchLocationsNear( center ) {
  58.         clearLocations();
  59.  
  60.         var radius = document.getElementById( 'radiusSelect' ).value;
  61.         var searchUrl = '/maps/genxml.php?lat=' + center.lat() + '&lng=' + center.lng() + '&radius=' + radius;
  62.         downloadUrl( searchUrl, function ( data ) {
  63.             var xml = parseXml( data );
  64.             var markerNodes = xml.documentElement.getElementsByTagName( "marker" );
  65.             var bounds = new google.maps.LatLngBounds();
  66.             for ( var i = 0; i < markerNodes.length; i++ ) {
  67.                 var name = markerNodes[ i ].getAttribute( "name" );
  68.                 var address = markerNodes[ i ].getAttribute( "address" );
  69.                 var distance = parseFloat( markerNodes[ i ].getAttribute( "distance" ) );
  70.                 var latlng = new google.maps.LatLng(
  71.                     parseFloat( markerNodes[ i ].getAttribute( "lat" ) ),
  72.                     parseFloat( markerNodes[ i ].getAttribute( "lng" ) ) );
  73.  
  74.                 createOption( name, distance, i );
  75.                 createMarker( latlng, name, address );
  76.                 bounds.extend( latlng );
  77.             }
  78.             map.fitBounds( bounds );
  79.             locationSelect.style.visibility = "visible";
  80.             locationSelect.onchange = function () {
  81.                 var markerNum = locationSelect.options[ locationSelect.selectedIndex ].value;
  82.                 google.maps.event.trigger( markers[ markerNum ], 'click' );
  83.             };
  84.         } );
  85.     }
  86.  
  87.     function createMarker( latlng, name, address ) {
  88.         var html = "<b>" + name + "</b>";
  89.         var marker = new google.maps.Marker( {
  90.             map: map,
  91.             position: latlng
  92.         } );
  93.         google.maps.event.addListener( marker, 'click', function () {
  94.             infoWindow.setContent( html );
  95.             infoWindow.open( map, marker );
  96.         } );
  97.         markers.push( marker );
  98.     }
  99.  
  100.     function createOption( name, distance, num ) {
  101.         var option = document.createElement( "option" );
  102.         option.value = num;
  103.         option.innerHTML = name + "(" + distance.toFixed( 1 ) + ")";
  104.         locationSelect.appendChild( option );
  105.     }
  106.  
  107.     function downloadUrl( url, callback ) {
  108.         var request = window.ActiveXObject ?
  109.             new ActiveXObject( 'Microsoft.XMLHTTP' ) :
  110.             new XMLHttpRequest;
  111.  
  112.         request.onreadystatechange = function () {
  113.             if ( request.readyState == 4 ) {
  114.                 request.onreadystatechange = doNothing;
  115.                 callback( request.responseText, request.status );
  116.             }
  117.         };
  118.  
  119.         request.open( 'GET', url, true );
  120.         request.send( null );
  121.     }
  122.  
  123.     function parseXml( str ) {
  124.         if ( window.ActiveXObject ) {
  125.             var doc = new ActiveXObject( 'Microsoft.XMLDOM' );
  126.             doc.loadXML( str );
  127.             return doc;
  128.         } else if ( window.DOMParser ) {
  129.             return ( new DOMParser ).parseFromString( str, 'text/xml' );
  130.         }
  131.     }
  132.  
  133.     function doNothing() {}
  134.  
  135.     //]]>
  136. </script>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top