Jak*_*son 1 google-maps google-maps-api-3 map-projections
我使用Google Maps API v3创建了自定义地图.这是一个虚构世界的矩形地图,而不是现实世界中的任何东西.
我一直在阅读有关如何在自定义Google地图中使用预测的文章.我需要使用投影,因为使用投影放置标记和区域,它们不会水平重复.无论如何,我从教程中提取了以下代码:
var tilesize = 256;
function MyProjection(){}
MyProjection.prototype.fromLatLngToPoint = function(latLng)
{
var x = latLng.lng() * tileSize;
var y = latLng.lat() * tileSize;
return new google.maps.Point(x, y);
};
MyProjection.prototype.fromPointToLatLng = function(point)
{
var lng = point.x * (1.0 / tileSize);
var lat = point.y * (1.0 / tileSize);
return new google.maps.LatLng(lat, lng);
};
function LatLngToPixels(latLng)
{
var pnt = MyProjection.prototype.fromLatLngToPoint(latLng);
return [pnt.x * 8, pnt.y * 8];
}
function PixelsToLatLng(pxs)
{
var pnt = {x: pxs[0] / 8, y: pxs[1] / 8};
return MyProjection.prototype.fromPointToLatLng(pnt);
}
Run Code Online (Sandbox Code Playgroud)
我已将它应用到我的地图上,似乎有效.但是,我试图弄清楚如何改变投影的规模.当我放置这样的标记时:
new google.maps.Marker(
{
map: map,
position: new google.maps.LatLng(0, 0)
});
Run Code Online (Sandbox Code Playgroud)
标记位于地图的左上角.如果我这样做:
new google.maps.Marker(
{
map: map,
position: new google.maps.LatLng(1, 1)
});
Run Code Online (Sandbox Code Playgroud)
标记位于右下角.
所以我的经度和纬度最低为0,最大值为1.如何更改上述功能以使比例更容易管理?喜欢0到90或0到180?在真实世界经度和纬度坐标方面更有意义的东西?或者说预测不可能吗?我对投影的想法有点困惑,究竟它们的最终目的是什么,所以也许我错过了这一点......
归档时间: |
|
查看次数: |
2880 次 |
最近记录: |