Google geocode example - gists · GitHub

文章推薦指數: 80 %
投票人數:10人

Google geocode example. GitHub Gist: instantly share code, notes, and snippets. Skiptocontent Allgists BacktoGitHub Signin Signup Sign in Sign up {{message}} Instantlysharecode,notes,andsnippets. SamSamskies/app.css LastactiveJan17,2020 Star 1 Fork 0 Star Code Revisions 2 Stars 1 Embed Whatwouldyouliketodo? Embed Embedthisgistinyourwebsite. Share Copysharablelinkforthisgist. Clonevia HTTPS ClonewithGitorcheckoutwithSVNusingtherepository’swebaddress. LearnmoreaboutcloneURLs DownloadZIP Googlegeocodeexample Raw app.css ThisfilecontainsbidirectionalUnicodetextthatmaybeinterpretedorcompileddifferentlythanwhatappearsbelow.Toreview,openthefileinaneditorthatrevealshiddenUnicodecharacters. LearnmoreaboutbidirectionalUnicodecharacters Showhiddencharacters #myMap{ width:800px; height:500px; } Raw app.js ThisfilecontainsbidirectionalUnicodetextthatmaybeinterpretedorcompileddifferentlythanwhatappearsbelow.Toreview,openthefileinaneditorthatrevealshiddenUnicodecharacters. LearnmoreaboutbidirectionalUnicodecharacters Showhiddencharacters $(document).ready(function(){ $('#geo').on('click',function(){ vargeocoder=newgoogle.maps.Geocoder(); varaddress=document.getElementById('address').value; geocoder.geocode({'address':address},function(results,status){ if(status==google.maps.GeocoderStatus.OK){ console.log(results[0].geometry.location.lat()) console.log(results[0].geometry.location.lng()) }else{ alert('Geocodewasnotsuccessfulforthefollowingreason:'+status); } }); }) }) //functioninitialize(){ //varmapOptions={ //center:newgoogle.maps.LatLng(-33.8688,151.2195), //zoom:13, //mapTypeId:google.maps.MapTypeId.ROADMAP //}; //varmap=newgoogle.maps.Map(document.getElementById('myMap'), //mapOptions); //varinput=/**@type{HTMLInputElement}*/(document.getElementById('address')); //varautocomplete=newgoogle.maps.places.Autocomplete(input); //autocomplete.bindTo('bounds',map); //varinfowindow=newgoogle.maps.InfoWindow(); //varmarker=newgoogle.maps.Marker({ //map:map //}); //google.maps.event.addListener(autocomplete,'place_changed',function(){ //infowindow.close(); //marker.setVisible(false); //input.className=''; //varplace=autocomplete.getPlace(); //if(!place.geometry){ ////Informtheuserthattheplacewasnotfoundandreturn. //input.className='notfound'; //return; //} ////Iftheplacehasageometry,thenpresentitonamap. //if(place.geometry.viewport){ //map.fitBounds(place.geometry.viewport); //}else{ //map.setCenter(place.geometry.location); //map.setZoom(17);//Why17?Becauseitlooksgood. //} //marker.setIcon(/**@type{google.maps.Icon}*/({ //url:place.icon, //size:newgoogle.maps.Size(71,71), //origin:newgoogle.maps.Point(0,0), //anchor:newgoogle.maps.Point(17,34), //scaledSize:newgoogle.maps.Size(35,35) //})); //marker.setPosition(place.geometry.location); //marker.setVisible(true); //varaddress=''; //if(place.address_components){ //address=[ //(place.address_components[0]&&place.address_components[0].short_name||''), //(place.address_components[1]&&place.address_components[1].short_name||''), //(place.address_components[2]&&place.address_components[2].short_name||'') //].join(''); //} //infowindow.setContent('

'+place.name+'
'+address); //infowindow.open(map,marker); //codeAddress() //}); //} //functioncodeAddress(){ //vargeocoder=newgoogle.maps.Geocoder(); //varaddress=document.getElementById('address').value; //geocoder.geocode({'address':address},function(results,status){ //if(status==google.maps.GeocoderStatus.OK){ //console.log(results[0].geometry.location.lat()) //console.log(results[0].geometry.location.lng()) ////map.setCenter(results[0].geometry.location); ////varmarker=newgoogle.maps.Marker({ ////map:map, ////position:results[0].geometry.location ////}); //}else{ //alert('Geocodewasnotsuccessfulforthefollowingreason:'+status); //} //}); //} //google.maps.event.addDomListener(window,'load',initialize); Raw index.html ThisfilecontainsbidirectionalUnicodetextthatmaybeinterpretedorcompileddifferentlythanwhatappearsbelow.Toreview,openthefileinaneditorthatrevealshiddenUnicodecharacters. LearnmoreaboutbidirectionalUnicodecharacters Showhiddencharacters TestingGoogleMapsAPI

Let'sDoThis!

Signupforfree tojointhisconversationonGitHub. Alreadyhaveanaccount? Signintocomment Youcan’tperformthatactionatthistime. Yousignedinwithanothertaborwindow.Reloadtorefreshyoursession. Yousignedoutinanothertaborwindow.Reloadtorefreshyoursession.



請為這篇文章評分?