[英]Google Maps - Get coordinates for UK Counties
I was wondering whether anyone could please advise how I can get the coordinates for UK counties to be able to add a polygon to google maps using the google maps API? 我想知道是否有人可以建议我如何获取英国县的坐标,以便能够使用Google Maps API向Google地图添加多边形?
I have looked at using https://nominatim.openstreetmap.org/details.php?place_id=198164455 to retrieve the OSM relation to be able to use http://polygons.openstreetmap.fr/ 我看过使用https://nominatim.openstreetmap.org/details.php?place_id=198164455来检索OSM关系以便能够使用http://polygons.openstreetmap.fr/
For example: Leicestershire OSM = 189890 例如:莱斯特郡OSM = 189890
http://polygons.openstreetmap.fr/index.py?id=189890 http://polygons.openstreetmap.fr/index.py?id=189890
I have used the coordinates for the area however I believe these are incorrect since the polygon appears in the middle of the sea rather than over the county. 我使用了该区域的坐标,但是我相信这些坐标是不正确的,因为多边形出现在海中而不是在县上空。
Can anyone please advise how I can get the coordinates for the UK counties to be able to add the polygon? 谁能建议我如何获取英国各县的坐标以添加多边形? I wasn't sure whether there are any tools that would generate these for you?
我不确定是否有任何工具可以为您生成这些工具?
My code: ( var leicestershire should have the coordinates of the county ) 我的代码:(莱斯特郡应该有该县的坐标)
function initialize() {
var pin = new google.maps.LatLng(52.374490, -0.713289);
var map = new google.maps.Map(document.getElementById('map-canvas'), {
zoom: 5,
//minZoom: 15,
//maxZoom: 15,
center: pin,
mapTypeId: google.maps.MapTypeId.ROADMAP,
overviewMapControl:true,
mapTypeControl:false,
zoomControl: true,
streetViewControl: false,
draggable: true
});
var marker = new google.maps.Marker({
position: pin,
map: map
});
var leicestershire = [];
var leicestershirePoly = [];
leicestershire.forEach(function(coordinate) {
var latlng = coordinate.split(",");
var lat = parseFloat(latlng[0]);
var lng = parseFloat(latlng[1]);
if(!isNaN(lat) && !isNaN(lng)) {
leicestershirePoly.push({lat: lat, lng: lng});
}else{
console.log(coordinate);
}
});
var leicesterRegion = new google.maps.Polygon({
paths: leicestershirePoly,
strokeColor: '#FF0000',
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: '#FF0000',
fillOpacity: 0.35
});
leicesterRegion.setMap(map);
}
google.maps.event.addDomListener(window, 'load', initialize);
Leicestershire resolves to 52.772571, -1.2052126
in Google Maps. 莱斯特郡在Google地图上解析为
52.772571, -1.2052126
。 The first line of coordinates in your example polygon is -1.5975472, 52.7004047
so obviously, latitude and longitude are inverted. 您的示例多边形中的第一行坐标是
-1.5975472, 52.7004047
因此显然,纬度和经度是倒置的。
In your forEach
loop, replace 在您的
forEach
循环中,替换
var lat = parseFloat(latlng[0]);
var lng = parseFloat(latlng[1]);
by 通过
var lat = parseFloat(latlng[1]);
var lng = parseFloat(latlng[0]);
That should be enough to fix the issue if the rest of your code is working. 如果您其余的代码都能正常工作,那么就足以解决该问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.