2

I have created a mobile map with Cloudmade Leaflet and have it so a number of markers are generated to coincide with LatLong values in a database. However, I can't figure out how to set the initial Map view to set the zoom and centre the map on the group of markers. I presume I need to use setBounds but for this I need to know what the NorthEast and SouthWest coordinates are.

Do I need to go through the whole array of marker coordinates to find the North-most, East-most, South-most and West-mode values or is there an easier way?

4

4 に答える 4

3

fitBounds() メソッドを使用できます。 リーフレット参照

于 2012-11-27T14:14:02.377 に答える
0

map.fitBounds(markers.getBounds());

動作するはずです...例と同じ名前を持っている場合..

于 2014-04-16T22:48:39.873 に答える
0

私は、次のようなことをするのが最も簡単な方法だと思います:

int minLat = int.MaxValue;
int minLong = int.MaxValue;
int maxLat = int.MinValue;
int maxLong = int.MinValue;

foreach (var point in coordinates) 
{
    minLat = Math.Min(point.Latitude(), minLat);
    minLong = Math.Min(point.Longitude(), minLong);
    maxLat = Math.Max(point.Latitude(), maxLat);
    maxLong = Math.Max(point.Longitude(), maxLong);
} 

これは、C# でうまく機能しました。

于 2012-07-31T11:02:49.677 に答える