画面にGoogleマップを設定しましたが、できるようにしたいのは、ユーザーが場所を入力して、この場所にリダイレクトできるようにすることです。次のページに例がありますhttps://developers.google.com/maps/location-based-appsは、場所を入力する最初のマップにあります。私が現在持っているコードはこれですが、テキストボックスに入力して新しい場所でマップを更新できるようにする方法に関する情報が見つかりません。
<script type="text/javascript">
//Javascript used to add Elements to the maps
// Arguments latitude, longitude, name
function addMarkersToMap(eventTitle,eventLongitude,eventLatitude)
{
markers.push({ lat: eventLatitude, lng: eventLongitude, name: eventTitle });
}
function initialize()
{
// Create the 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 the markers ad infowindows.
for (index in markers) addMarker(markers[index]);
function addMarker(data)
{
// Create the marker
var marker = new google.maps.Marker(
{
position: new google.maps.LatLng(data.lat, data.lng),
map: map,
title: data.name
});
// Create the infowindow with two DIV placeholders
// One for a text string, the other for the 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 the infowindow on marker click
google.maps.event.addListener(marker, "click", function()
{
infowindow.open(map, marker);
});
// Handle the DOM ready event to create the StreetView panorama
// as it can only be created once the DIV inside the infowindow is loaded in the 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: An error occur while fetching information from the Google API');
});
}
else
{
alert("Your browser doesn't support geolocations, please consider downloading Google Chrome");
}
}
</script>
<div id="map_canvas" style="width:100%; height:400px"></div>