addGeoJson 函数反纬度和经度?
addGeoJson Function inverse Lat and Lng?
我正在开发 google 地图函数以在地图中显示 GEOJson 数据。
根据网络,以下几点在蒙特利尔:
- 点 1:lat = 45.555 和 lng = -73.555
- 点 2:lat = 45.666 和 lng = -73.666
http://www.latlong.net/c/?lat=45.666&long=-73.666
所以我构建了我的 GEOJson 数据如下(在蒙特利尔显示两个标记):
var data_default = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [45.555, -73.555]
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [45.666, -73.666]
}
}
] };
但是,对于此数据,以下函数:
map.data.addGeoJson(data);
没有指出蒙特利尔的点....要有蒙特利尔我应该反转"coordinates"的纬度和lng ..所以我的两个点应该有以下坐标:[-73.555, 45.555 ] [-73.666, 45.666] 而不是 [45.555, -73.555 ] [45.666,-73.666]
有没有人可以向我解释为什么 Google 地图 api 的 addGeoJson 以相反的方式读取点?
谢谢
GeoJSON 指定坐标为 [longitude,latitude]。你的坐标倒过来了。
来自the spec:
Point coordinates are in x, y order (easting, northing for projected coordinates, longitude, latitude for geographic coordinates):
代码片段:
function initialize() {
var map = new google.maps.Map(
document.getElementById("map_canvas"), {
center: new google.maps.LatLng(45.555, -73.555),
zoom: 10,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var data_default = {
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [-73.555, 45.555]
}
}, {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [-73.666, 45.666]
}
}]
};
map.data.addGeoJson(data_default);
}
google.maps.event.addDomListener(window, "load", initialize);
html,
body,
#map_canvas {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px
}
<script src="https://maps.googleapis.com/maps/api/js"></script>
<div id="map_canvas"></div>
我正在开发 google 地图函数以在地图中显示 GEOJson 数据。
根据网络,以下几点在蒙特利尔:
- 点 1:lat = 45.555 和 lng = -73.555
- 点 2:lat = 45.666 和 lng = -73.666
http://www.latlong.net/c/?lat=45.666&long=-73.666
所以我构建了我的 GEOJson 数据如下(在蒙特利尔显示两个标记):
var data_default = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [45.555, -73.555]
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [45.666, -73.666]
}
}
] };
但是,对于此数据,以下函数:
map.data.addGeoJson(data);
没有指出蒙特利尔的点....要有蒙特利尔我应该反转"coordinates"的纬度和lng ..所以我的两个点应该有以下坐标:[-73.555, 45.555 ] [-73.666, 45.666] 而不是 [45.555, -73.555 ] [45.666,-73.666]
有没有人可以向我解释为什么 Google 地图 api 的 addGeoJson 以相反的方式读取点?
谢谢
GeoJSON 指定坐标为 [longitude,latitude]。你的坐标倒过来了。
来自the spec:
Point coordinates are in x, y order (easting, northing for projected coordinates, longitude, latitude for geographic coordinates):
代码片段:
function initialize() {
var map = new google.maps.Map(
document.getElementById("map_canvas"), {
center: new google.maps.LatLng(45.555, -73.555),
zoom: 10,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var data_default = {
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [-73.555, 45.555]
}
}, {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [-73.666, 45.666]
}
}]
};
map.data.addGeoJson(data_default);
}
google.maps.event.addDomListener(window, "load", initialize);
html,
body,
#map_canvas {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px
}
<script src="https://maps.googleapis.com/maps/api/js"></script>
<div id="map_canvas"></div>