我目前正在使用Google地图列出国家,地区和城市。但是我有一个问题。我有三种可能:绿色表示无警告,黄色表示无警告,红色表示有严重警告。
问题在于,地区无法占领该地区的城市。让我们以奥地利为例。奥地利有一个名为Niederösterreich的地区。奥地利需要贴有绿色标签,而下德斯特赖克的所有城市都需要贴有黄色标签。
它可以在某些城市使用,例如位于下埃斯特雷希(Niederösterreich)的圣珀尔滕(SanktPölten),但也位于下埃斯特雷希(Niederösterreich)的Zwettl却无法使用。
<script>
google.maps.visualRefresh = true;
var h = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
$('#world-map').css('height', h - 80);
var map, centerLat, centerLng, zoom, addrMarker;
var geocoder = new google.maps.Geocoder();
if (h >= 955) {
centerLat = 20.0;
centerLng = 10.0;
zoom = 3;
} else if (h <= 678 && h < 955) {
centerLat = 42.0;
centerLng = 0.0;
zoom = 2;
} else {
centerLat = 0.0;
centerLng = 0.0;
zoom = 2;
}
var countries = "{!! $countries !!}";
countries = countries.replace(/[\(\)']/g, '').split(',');
var regions = "{!! $regions !!}";
regions = regions.replace(/[\(\)']/g, '').split(',');
var qstatus = "{!! $status !!}";
qstatus = qstatus.replace(/[\(\)']/g, '').split(',');
var red = "{!! $red !!}";
red = red.replace(/[\(\)']/g, '').split(',');
var orange = "{!! $orange !!}";
orange = orange.replace(/[\(\)']/g, '').split(',');
var yellow = "{!! $yellow !!}";
yellow = yellow.replace(/[\(\)']/g, '').split(',');
var green = "{!! $green !!}";
green = green.replace(/[\(\)']/g, '').split(',');
function initialize() {
map = new google.maps.Map(document.getElementById('world-map'), {
center: new google.maps.LatLng(centerLat,centerLng),
zoom: zoom
});
var input = document.getElementById('search_address');
var options = {
types: ['(regions)']
};
var autocomplete = new google.maps.places.Autocomplete(input, options);
}
function performSearch() {
if (addrMarker != null) { addrMarker.setMap(null); }
var address = $('#search_address').val();
geocoder.geocode({'address': address}, function(results, status) {
if (status === google.maps.GeocoderStatus.OK) {
var user_point = results[0].geometry.location;
console.log(results);
var add = results[0].address_components;
var addIso, quarantine;
var messages = [];
messages['green'] = '<div style="width:10%;height:100px;float:left;background-color: green;margin:10px 0 10px 0"></div><div style="width:85%;float:left;margin-left:5%;margin-top:10px"><h4>' + results[0].formatted_address + '</h4><p>Ophold i området giver <strong>ikke karantæne</strong></p></div>';
messages['yellow'] = '<div style="width:10%;height:110px;float:left;background-color: yellow;margin:10px 0 10px 0"></div><div style="width:85%;float:left;margin-left:5%;margin-top:10px"><h4>' + results[0].formatted_address + '</h4><p>Ophold i området giver <strong>4 ugers karantæne fra 1. april til 30. november</strong> grundet risiko for west nile virus (WNV) og andre infektionssygdomme, der kan overføres ved blodtransfusion.</p></div>';
messages['orange'] = '<div style="width:10%;height:130px;float:left;background-color: orange;margin:10px 0 10px 0"></div><div style="width:85%;float:left;margin-left:5%;margin-top:10px"><h4>' + results[0].formatted_address + '</h4><p>Ophold i området giver <strong>4 ugers karantæne hele året</strong>. Dette er grundet risiko for diverse importerede sygdomme, eksempelvis dengue virus og chikungunya virus og andre infektionssygdomme, der kan overføres ved blodtransfusion.</p></div>';
messages['red'] = '<div style="width:10%;height:100px;float:left;background-color: red;margin:10px 0 10px 0"></div><div style="width:85%;float:left;margin-left:5%;margin-top:10px"><h4>' + results[0].formatted_address + '</h4><p>Ophold i området giver <strong>6 måneders karantæne</strong> grundet risiko for malaria og andre infektionssygdomme, der kan overføres ved blodtransfusion.</p></div>';
messages['undefined'] = '<div style="width:10%;height:120px;float:left;background-color: red;margin:10px 0 10px 0"></div><div style="width:85%;float:left;margin-left:5%;margin-top:10px"><h4>' + results[0].formatted_address + '</h4><p>Området er ikke kategoriseret i forhold til karantæne. Kontakt din blodbank via mail eller telefon for yderligere information.</p></div>';
for (var i = 0; i < add.length; i++) {
if (add[i].types[0] == 'country') {
if (countries.indexOf(add[i]['short_name']) > -1) {
for (var j = 0; j < add.length; j++) {
if (add[i]['short_name'] === 'KR' && add[j]['short_name'] === 'Seoul') {
quarantine = qstatus[regions.indexOf('Seoul')];
} else if (add[i]['short_name'] === 'VE' && add[j]['short_name'] == 'Isla de Margarita') {
quarantine = qstatus[regions.indexOf('Isla de Margarita')];
} else if (add[i]['short_name'] === 'TR') {
if (add[j]['short_name'] == 'Mugla' || add[j]['short_name'] == 'Muğla Province') {
quarantine = qstatus[regions.indexOf('Muğla')];
} else if (add[j]['short_name'] == 'Izmir' || add[j]['short_name'] == 'Çeşme') {
quarantine = qstatus[regions.indexOf('İzmir Province')];
} else if (add[j]['short_name'] == 'Istambul' || add[j]['short_name'] == 'Istanbul-provinsen') {
quarantine = qstatus[regions.indexOf('İstanbul')];
}
} else if (add[i]['short_name'] === 'PT') {
if (add[j]['short_name'] == 'Faro' || add[j]['short_name'] == 'Faro District') {
quarantine = qstatus[regions.indexOf('Faro')];
}
} else if (add[i]['short_name'] === 'AT' && add[j]['short_name'] == 'Wien') {
quarantine = qstatus[regions.indexOf('Wien')];
} else if (add[i]['short_name'] === 'AT' && add[j]['short_name'] == 'Niederösterreich') {
quarantine = qstatus[regions.indexOf('Niederösterreich')];
} else if (add[i]['short_name'] === 'FR' && add[j]['short_name'] == 'Gard') {
quarantine = qstatus[regions.indexOf('Gard')];
}else if (add[i]['short_name'] === 'FR' && add[j]['short_name'] == 'Alpes-Maritimes') {
quarantine = qstatus[regions.indexOf('Alpes-Maritimes')];
}
if (add[j].types[0] == 'administrative_area_level_1') {
if (regions.indexOf(add[j]['long_name']) > -1) {
quarantine = qstatus[regions.indexOf(add[j]['long_name'])];
}
}
}
if (!quarantine) {
addIso = add[i]['short_name'];
if (green.indexOf(addIso) > -1) {
quarantine = 'green';
} else if (yellow.indexOf(addIso) > -1) {
quarantine = 'yellow';
} else if (orange.indexOf(addIso) > -1) {
quarantine = 'orange';
} else if (red.indexOf(addIso) > -1) {
quarantine = 'red';
}
}
} else {
addIso = add[i]['short_name'];
if (green.indexOf(addIso) > -1) {
quarantine = 'green';
} else if (yellow.indexOf(addIso) > -1) {
quarantine = 'yellow';
} else if (orange.indexOf(addIso) > -1) {
quarantine = 'orange';
} else if (red.indexOf(addIso) > -1) {
quarantine = 'red';
}
}
} else if (add[0]['short_name'] === 'Gazastriben' || add[0]['short_name'] === 'Vestbredden') {
addIso = 'PS';
if (green.indexOf(addIso) > -1) {
quarantine = 'green';
} else if (yellow.indexOf(addIso) > -1) {
quarantine = 'yellow';
} else if (orange.indexOf(addIso) > -1) {
quarantine = 'orange';
} else if (red.indexOf(addIso) > -1) {
quarantine = 'red';
}
} else if (add[0]['short_name'] === 'Pristina') {
addIso = 'XK';
if (green.indexOf(addIso) > -1) {
quarantine = 'green';
} else if (yellow.indexOf(addIso) > -1) {
quarantine = 'yellow';
} else if (orange.indexOf(addIso) > -1) {
quarantine = 'orange';
} else if (red.indexOf(addIso) > -1) {
quarantine = 'red';
}
}
}
if (quarantine === '') {
quarantine = 'undefined';
}
map.setCenter(user_point);
map.setZoom(7);
addrMarker = new google.maps.Marker({
position: user_point,
map: map,
icon: 'https://maps.gstatic.com/mapfiles/ms2/micons/man.png',
animation: google.maps.Animation.DROP,
title: address
});
var infoWin = new google.maps.InfoWindow({
content: messages[quarantine]
});
infoWin.open(map, addrMarker);
google.maps.event.addDomListener(addrMarker, 'click', function() {
infoWin.open(map, addrMarker);
});
} else {
alert("Problem med adresse");
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);
$('#search').on('click', function() {
if ($('#search_address').val() !== "") {
performSearch();
}
});
$('#search_address').on('keydown', function(e) {
var key = e.keyCode ? e.keyCode : e.which;
if (key === 13) {
$('#search').click();
return false;
}
});
</script>
答案 0 :(得分:0)
@FabianGillenius
我发现了问题,这是由于Google Maps API造成的。
它在丹麦和其他国家/地区称为Niederösterreich,但在Google Maps API中被列为“下奥地利州”,但现在可以使用。
感谢您的帮助