Sunday, 15 August 2010

ruby on rails - Google Maps API text search location -



ruby on rails - Google Maps API text search location -

i have set google maps on screen want able allow user come in location redirect location. have illustration on next page https://developers.google.com/maps/location-based-apps has in first maps, come in location. code have can't find info on how come in text box allow refresh map new location.

<script type="text/javascript"> //javascript used add together elements maps // arguments latitude, longitude, name function addmarkerstomap(eventtitle,eventlongitude,eventlatitude) { markers.push({ lat: eventlatitude, lng: eventlongitude, name: eventtitle }); } function initialize() { // create map var lat, lon, myoptions; if(navigator.geolocation) { navigator.geolocation.getcurrentposition(function(position) { lat = <%= @event.latitude %>; lon = <%= @event.longitude %>; myoptions = { center: new google.maps.latlng(lat, lon), zoom: 12, maptypeid: google.maps.maptypeid.roadmap }; var map = new google.maps.map(document.getelementbyid("map_canvas"), myoptions); // create markers advertisement infowindows. (index in markers) addmarker(markers[index]); function addmarker(data) { // create marker var marker = new google.maps.marker( { position: new google.maps.latlng(data.lat, data.lng), map: map, title: data.name }); // create infowindow 2 div placeholders // 1 text string, other streetview panorama. var content = document.createelement("div"); var title = document.createelement("div"); title.innerhtml = data.name; content.appendchild(title); var streetview = document.createelement("div"); streetview.style.width = "200px"; streetview.style.height = "200px"; content.appendchild(streetview); var infowindow = new google.maps.infowindow( { content: content }); // open infowindow on marker click google.maps.event.addlistener(marker, "click", function() { infowindow.open(map, marker); }); // handle dom ready event create streetview panorama // can created 1 time div within infowindow loaded in dom. google.maps.event.addlisteneronce(infowindow, "domready", function() { var panorama = new google.maps.streetviewpanorama(streetview, { navigationcontrol: false, enableclosebutton: false, addresscontrol: false, linkscontrol: false, visible: true, position: marker.getposition() }); }); } }, function(error) { alert('error: error occur while fetching info google api'); }); } else { alert("your browser doesn't back upwards geolocations, please consider downloading google chrome"); } } </script> <div id="map_canvas" style="width:100%; height:400px"></div>

what looking geocoding not geolocation.

the function findlocation()below uses geocoding find location textbox address. uses version 3 of api opposed v2 in accepted answer. version 2 of maps api deprecated, , warranted until 19 may 2013 , should not used in new applications.

function findlocation() { var address = document.getelementbyid('address').value; geocoder.geocode( { 'address': address}, function(results, status) { if (status == google.maps.geocoderstatus.ok) { map.setcenter(results[0].geometry.location); var marker = new google.maps.marker({ map: map, position: results[0].geometry.location }); } else { alert('location not found: ' + status); } }); }

ruby-on-rails google-maps geolocation

No comments:

Post a Comment