我有一个谷歌地图api以及2个输入和一个提交按钮,但输入和提交按钮似乎没有正确设置风格,并且不会在地图上方的单行中出现。我还尝试将地图的位置和输入更改为绝对,但随后表单变得无法响应。我是这个领域的新手,请帮助我相应地设置页面样式,而不会破坏页面的功能。
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<style>
html, body {
height: 100%;
width:100%;
}
.fluid-wrapper
{
position:relative;
width:100%;
height:100%;
}
#map-canvas
{
position:absolute;
height:100%;
width:100%;
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=places"></script>
<script>
var poly, map,place,place1;
var locations=new Array();
var bounds=new google.maps.LatLngBounds();
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(-33.8688, 151.2195),
zoom: 13
};
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var input = /** @type {HTMLInputElement} */
(
document.getElementById('input'));
var input1 = (document.getElementById('input1'));
map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);
map.controls[google.maps.ControlPosition.TOP_LEFT].push(input1);
var autocomplete = new google.maps.places.Autocomplete(input);
autocomplete.bindTo('bounds', map);
var autocomplete1 = new google.maps.places.Autocomplete(input1);
autocomplete1.bindTo('bounds', map);
var infowindow = new google.maps.InfoWindow();
var marker = new google.maps.Marker({
map: map,
anchorPoint: new google.maps.Point(0, -29)
});
var marker1 = new google.maps.Marker({
map: map,
anchorPoint: new google.maps.Point(0, -29)
});
var polyOptions = {
strokeColor: '#000000',
strokeOpacity: 1.0,
strokeWeight: 3
};
poly = new google.maps.Polyline(polyOptions);
google.maps.event.addDomListener(document.getElementById('submit'), 'click', function () {
marker.setVisible(true);
marker1.setVisible(true);
// map.fitBounds(place.geometry.viewport);
//map.setZoom(5);
for (var i = 0, LtLgLen = locations.length; i < LtLgLen; i++) {
// And increase the bounds to take this point
bounds.extend (locations[i]);
}
map.fitBounds(bounds);
// map.setCenter(new google.maps.LatLng(((place.geometry.location.k+place1.geometry.location.k)/2),((place.geometry.location.D+place1.geometry.location.D)/2));
poly.setMap(map);
});
google.maps.event.addListener(autocomplete, 'place_changed', function () {
infowindow.close();
marker.setVisible(false);
place = autocomplete.getPlace();
if (!place.geometry) {
return;
}
// If the place has a geometry, then present it on a map.
if (place.geometry.viewport) {
// map.fitBounds(place.geometry.viewport);
} else {
map.setCenter(place.geometry.location);
map.setZoom(17); // Why 17? Because it looks good.
}
marker.setIcon( /** @type {google.maps.Icon} */ ({
url: place.icon,
size: new google.maps.Size(71, 71),
origin: new google.maps.Point(0, 0),
anchor: new google.maps.Point(17, 34),
scaledSize: new google.maps.Size(35, 35)
}));
marker.setPosition(place.geometry.location);
locations.push(place.geometry.location);
// marker.setVisible(true);
poly.getPath().setAt(0, marker.getPosition());
// var myLatLng=(place.geometry.location.k,place.geometry.location.D);
//bounds.extend(myLatLng);
var address = '';
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('<div><strong>' + place.name + '</strong><br>' + address);
// infowindow.open(map, marker);
});
google.maps.event.addListener(autocomplete1, 'place_changed', function () {
infowindow.close();
marker1.setVisible(false);
place1 = autocomplete1.getPlace();
if (!place1.geometry) {
return;
}
// If the place has a geometry, then present it on a map.
if (place1.geometry.viewport) {
//map.fitBounds(place1.geometry.viewport);
} else {
map.setCenter(place1.geometry.location);
map.setZoom(11); // Why 17? Because it looks good.
}
marker1.setIcon( /** @type {google.maps.Icon} */ ({
url: place1.icon,
size: new google.maps.Size(71, 71),
origin: new google.maps.Point(0, 0),
anchor: new google.maps.Point(17, 34),
scaledSize: new google.maps.Size(35, 35)
}));
marker1.setPosition(place1.geometry.location);
locations.push(place1.geometry.location);
// marker1.setVisible(true);
poly.getPath().setAt(1, marker1.getPosition());
//var myLatLng=(place1.geometry.location.k, place1.geometry.location.D);
//bounds.extend(myLatLng);
var address = '';
if (place1.address_components) {
address = [
(place1.address_components[0] && place1.address_components[0].short_name || ''), (place1.address_components[1] && place1.address_components[1].short_name || ''), (place1.address_components[2] && place1.address_components[2].short_name || '')].join(' ');
}
// infowindow.setContent('<div><strong>' + place.name + '</strong><br>' + address);
// infowindow.open(map, marker1);
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div class="fluid-wrapper">
<nav class="navbar navbar-default">
<div class="nav navbar-nav">
<div class="pull-left">
<input id="input" class="form-control" type="text" placeholder="Enter a location" style="width:300px; height:30px;border-width:2px;
border-style:solid; margin-top:10px;padding-left:4px;" />
<input id="input1" class="form-control" type="text" placeholder="Enter another location" style="width:300px; height:30px;margin- left:20px;margin-top:10px; border-width:2px;
border-style:solid; padding-left:4px;"/>
</div>
</div>
<div class="nav navbar-nav">
<div class="pull-right">
<input type="submit" class="btn btn-info" name="submit" id="submit" value="SUBMIT" style="margin-left:720px;margin-top:-18px;" />
</div>
</div>
</nav>
<div class="map_canvas" id="map-canvas"></div>
</div>
</body>
</html>