Google maps JS在地图顶部生成地理代码搜索
谷歌看起来很简单,这就是我所需要的全部功能。不过,我有多个谷歌地图是通过qTip工具提示生成的,所以我希望在每个地图的顶部(而不是上方)有一个地理编码搜索字段。查看我当前的。最好的方法是什么?在div上使用一些合适的CSS。看这里 您必须取消选中“SP”,它才能在我所在城市以外工作Google maps JS在地图顶部生成地理代码搜索,google-maps,google-maps-api-3,Google Maps,Google Maps Api 3,谷歌看起来很简单,这就是我所需要的全部功能。不过,我有多个谷歌地图是通过qTip工具提示生成的,所以我希望在每个地图的顶部(而不是上方)有一个地理编码搜索字段。查看我当前的。最好的方法是什么?在div上使用一些合适的CSS。看这里 您必须取消选中“SP”,它才能在我所在城市以外工作 html { height: 100% } body { height: 100%; margin: 0; padding: 0 } #map_canvas { height: 100% } #me
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map_canvas { height: 100% }
#menu {
position: absolute;
top: 0px;
left: 0px;
padding: 0px;
font-family: Arial, sans-serif;
}
... ... ...
<div id="map_canvas"></div>
<div id="menu">
<b>address:</b>
<input id="text_address" type="text" size="60" onkeyup="checkReturn(event)">
<input id="check_sp" type="checkbox" checked="checked">SP
<input type="button" value="clear" onclick="document.getElementById('text_address').value=''; document.getElementById('text_address').focus()">
<input id="button3" type="button" value="clear markers" onclick="clearMarkers()">
</div>
html{height:100%}
正文{高度:100%;边距:0;填充:0}
#地图画布{高度:100%}
#菜单{
位置:绝对位置;
顶部:0px;
左:0px;
填充:0px;
字体系列:Arial,无衬线;
}
... ... ...
地址:
服务提供商
已解决。我基本上使用jQuery将我的搜索框附加到qTip的容器中,然后用jQuery live()监听搜索按钮上的点击。我懒得创建新的小提琴,但这里有一些代码:
在qTip的“渲染”事件中:
var geocoder;
geocoder = new google.maps.Geocoder();
...
api.map = new google.maps.Map(container[0], myOptions);
$(container).append('<div class="geosearch"><input type="text" class="geosearchinput" value="" /><button type="button" class="geosearchbutton">Search</button></div>');
...
$('button.geosearchbutton').live('click', function() {
var address = $(this).prev('input.geosearchinput').val();
geocoder.geocode({ 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
... add marker and handle markers array ...
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
});
var地理编码器;
geocoder=新的google.maps.geocoder();
...
api.map=new google.maps.map(容器[0],myOptions);
$(容器).append('Search');
...
$('button.geosearchbutton').live('click',function()){
var address=$(this.prev('input.geosearchinput').val();
geocoder.geocode({'address':address},函数(结果,状态){
if(status==google.maps.GeocoderStatus.OK){
map.setCenter(结果[0].geometry.location);
…添加标记和句柄标记数组。。。
}否则{
警报('地理编码因以下原因未成功:'+状态);
}
});
});
。因为我在不同的位置(在工具提示中)生成了多个贴图,所以我相信我必须让JS在生成每个贴图之后立即生成表单字段。(看我的小提琴)这正是让我困惑的地方。我会继续玩它。。。