本文介绍了Google地图反向GeoCoding获取国家名称,英国国家的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用谷歌地图Api V3并使用反向地理编码来查找所点击的国家/地区的名称。
对于除英国以外的国家/地区的大多数国家/地区,这似乎表现良好。英国由英格兰,苏格兰,威尔士和北爱尔兰组成,分别为4不同的国家,但谷歌地图(和大多数其他国家的东西)看到他们都只是英国。
我需要知道英国哪个特定国家被点击而不仅仅是英国被点击了!
我正在使用以下javascript,我目前只是使用视觉工作室观看功能来挖掘结果[ 1]来查看包含的内容。
函数初始化(){
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(51.8052184317649,-4.965819906250006);
var myOptions = {
zoom:5,
center:latlng,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById(map_canvas),myOptions);
google.maps.event.addListener(地图,'点击',功能(事件){
if(confirm('这是您希望您的公司的位置?') )){
geocoder.geocode({'latLng':event.latLng},function(results,status){
if(status == google.maps.GeocoderStatus.OK){
if(results [1]){
}
}
});
}
});
}
如果我点击地图放大很远的国家名称(即威尔士)返回类型administrative_area_level_1和政治,但是当你放大时,它不再存在,因为它只是给出了不包含Wales的地址。
解决方案无法解决如何将地理代码反转到英国国家因为我认为这实际上是不可能的!
使用邮政编码并通过这些国家制定国家结束!
不是最好的,但它适用于我!
I am using google maps Api V3 and using reverse geocoding to find the name of a country clicked on.This appears to work fine for most countries except the countries within the UK.
The UK consists of England, Scotland, Wales and Northern Ireland, which are 4 separate countries, but google maps (and most other country things) see them all as just "UK".
I need to know which particular country within the UK has been clicked and not just that the UK has been clicked!
I am using the following javascript and I am currently just using visual studios "watch" feature to dig down into "results[1]" to see what is contained.
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(51.8052184317649, -4.965819906250006);
var myOptions = {
zoom: 5,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
google.maps.event.addListener(map, 'click', function (event) {
if (confirm('Is this the location you would like to you for your company?')) {
geocoder.geocode({ 'latLng': event.latLng }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
}
}
});
}
});
}
If I click when the map is zoomed quite far out the country name (ie Wales) comes back with types "administrative_area_level_1" and "political" but when you zoom in it's no longer there as it just gives the address which doesn't contain "Wales".
Does anyone know how I get round this? I'm sure other Brits have come across this?
解决方案
Couldn't work out how to reverse geocode to get a UK country as I think it's actually impossible!
Ended up using postcodes and working out countries by that!Not the best, but it works for me!
这篇关于Google地图反向GeoCoding获取国家名称,英国国家的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!