我花了整整一天看文档和示例,但我把自己翻了出来。我希望我可以指导正确的方式来做到这一点。我正在使用jQuery。添加geocoded谷歌地图div div
我们的目标是制作一张地图,向学生展示that a story所指的国家。我已经使用cut&paste solution来实现它,但是在切换div时无效 - 长话短说,我觉得我需要重做它,但是有点超出我的深度。我发现elsewhere on here地址解析的代码:
var geocoder = new google.maps.Geocoder();
var address = $("#infopanel .map a.header").text();
map = $("#infopanel .map div");
geocoder.geocode({ 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var latitude = results[0].geometry.location.lat();
var longitude = results[0].geometry.location.lng();
}
});
这是添加地图代码,但请注意,我不能工作,如何让地理编码的结果到的MapOptions中心变量:
var mapOptions = {
center: new google.maps.LatLng(*geocoded-data*),
zoom: 3,
mapTypeId: google.maps.MapTypeId.TERRAIN,
panControl: false,
zoomControl: true,
mapTypeControl: false,
scaleControl: false,
streetViewControl: false,
overviewMapControl: false
};
new google.maps.Map(map,mapOptions);
这里是的slideToggle代码与this answer调整大小/中心解决方案,但同样,我该如何让地理编码数据导入setCenter:
$("#infopanel ul li > div").slideToggle("fast"); // hide the content
$("#infopanel a.header").click(function(e){ // toggle the content.
var hascontent = $(this).next("div");
if (hascontent.length == 1) {
e.preventDefault();
$(this).next().slideToggle("slow", function() {
google.maps.event.trigger(map, "resize"); // resize map
map.setCenter(*geocoded-data*); // center map
});
}
});
为了方便起见,下面是它将全部使用的HTML:
<li class="map"><a href="" class="header">Zimbabwe</a>
<div style="width:220px;height:220px;"><a href="http://maps.google.com.au/maps?q=Zimbabwe&z=3">Find Zimbabwe on Google Maps</a></div>
</li>
如何连接这三者之间的点?
我在阅读完这个问题后通过使用goMap插件解决了这个问题(http://stackoverflow.com/q/10987802/43465)。我仍然不确定上述问题的答案。 – Daniel