【发布时间】:2014-08-12 04:18:59
【问题描述】:
我为我的 Rails 应用程序编写了一个代码,使用以下代码在谷歌地图上显示一些位置:
var myOptions = {
zoom: 2,
center: new google.maps.LatLng(71.1333,27.7000, 13), // **I need to set the center from the locations in here.**
mapTypeId: 'terrain'
};
map = new google.maps.Map($('#search_map_canvas')[0], myOptions);
var addresses = <%=raw search_offering_addressess.to_json %>;
for (var x = 0; x < addresses.length; x++) {
$.getJSON('http://maps.googleapis.com/maps/api/geocode/json?address='+addresses[x]+'&sensor=false', null, function (data) {
var p = data.results[0].geometry.location
var latlng = new google.maps.LatLng(p.lat, p.lng);
new google.maps.Marker({
position: latlng,
map: map
});
});
}
这里,search_offering_addressess 包含一个位置数组。例如。 [“柏林,德国”,“苏黎世,瑞士”,....]
如何找到这些位置的中点?我的地图错过了一些位置标记。
【问题讨论】: