Created
May 19, 2018 10:58
-
-
Save turigabor/bf250c5bd5680b981c5abb400564dde4 to your computer and use it in GitHub Desktop.
cookieless google maps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html><head><title>Google Maps</title> | |
| <meta charset="utf-8" /> | |
| <style type="text/css">html,body{width:100%;height:100%;margin:0;padding:0;}</style> | |
| <meta name="robots" content="noindex, nofollow" /> | |
| <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1" /> | |
| <script type="text/javascript"> | |
| var address = getParamter('q'); | |
| document.title = address + ' - ' + document.title; | |
| function getParamter (name) { | |
| var re = new RegExp('[?&]' + name.replace(/[\[\]]/g, '\\$&') + '(=([^&#]*)|&|#|$)'), | |
| results = re.exec(document.location.href); | |
| if (results && results[2]) { | |
| return decodeURIComponent(results[2].replace(/\+/g, ' ')); | |
| } | |
| } | |
| function renderMap (center) { | |
| var options = { | |
| zoom: 17, | |
| center: center, | |
| mapTypeControl: true, | |
| mapTypeControlOptions: { | |
| style: google.maps.MapTypeControlStyle.DROPDOWN_MENU | |
| }, | |
| navigationControl: true, | |
| mapTypeId: google.maps.MapTypeId.ROADMAP | |
| }; | |
| var map = new google.maps.Map(document.body, options); | |
| var infowindow = new google.maps.InfoWindow({ | |
| content: address, | |
| size: new google.maps.Size(150,50) | |
| }); | |
| var marker = new google.maps.Marker({ | |
| position: map.getCenter(), | |
| map: map, | |
| title: address | |
| }); | |
| google.maps.event.addListener(marker, 'click', function () { | |
| infowindow.open(map, marker); | |
| }); | |
| return map; | |
| } | |
| function initialize () { | |
| var pattern1 = /^([0-9]+)°([0-9]+)'([0-9\.]+)"N ([0-9]+)°([0-9]+)'([0-9\.]+)"E$/; | |
| if (pattern1.test(address)) { | |
| var t = address.split(pattern1); | |
| var lat = parseInt(t[1]) + (parseInt(t[2]) / 60) + (parseFloat(t[3]) / 3600); | |
| var lng = parseInt(t[4]) + (parseInt(t[5]) / 60) + (parseFloat(t[6]) / 3600); | |
| renderMap({lat: lat, lng: lng}); | |
| return; | |
| } | |
| var pattern2 = /^([0-9\.]+),? ([0-9\.]+)$/; | |
| if (pattern2.test(address)) { | |
| var t = address.split(pattern2); | |
| renderMap({lat: parseFloat(t[1]), lng: parseFloat(t[2])}); | |
| return; | |
| } | |
| var geocoder = new google.maps.Geocoder(); | |
| geocoder.geocode({address: address}, function (results, status) { | |
| if (status !== google.maps.GeocoderStatus.OK) { | |
| document.body.innerHTML = 'Geocode was not successful for the following reason: ' + status; | |
| return; | |
| } | |
| var map = renderMap(results[0].geometry.location); | |
| if (results[0].geometry.bounds) { | |
| map.fitBounds(results[0].geometry.bounds); | |
| } | |
| }); | |
| } | |
| </script> | |
| <script type="text/javascript" async defer src="https://maps.google.com/maps/api/js?key=YOUR_KEYc&callback=initialize"></script> | |
| </head> | |
| <body></body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment