谷歌地图地理编码器不如谷歌地图准确 [英] Google Map geocoder not as accurate as a Google maps
问题描述
我有一个数据库,其中包含精确到建筑物级别的地址。当我手动将这些手动放入Google地图搜索时,Google地图发现它们没有问题 - 标记出现在正确的建筑物的正上方。不过,当我使用下面的代码将这些相同的地址传递给Google Maps API地址解析器时,标记只会显示在街道上,而不是建筑物中。
我如何提高准确性?
HTML / PHP:
< div id =addressline><?php echo theaddress(); ?>< / DIV>
JS:
function myGeocodeFirst(){
geocoder = new google.maps.Geocoder();
geocoder.geocode({'address':document.getElementById(addressline)。innerHTML},
function(results,status){
if(status == google .maps.GeocoderStatus.OK){
firstLoc = results [0] .geometry.location;
map = new google.maps.Map(document.getElementById(map_canvas),
{
center:firstLoc,
zoom:15,
mapTypeId:google.maps.MapTypeId.ROADMAP
});
markers = new google.maps.Marker({
position:firstLoc,
map:map,
});
}
else {
document.getElementById(text_status) .value = status;
}
}
);
}
window.onload = myGeocodeFirst;
Google地图使用多种不同的数据来源定位在地图上搜索结果。
您看到的正确条目是Places数据库条目。请参阅此页面并输入您的搜索字符串(St Clement's Church,Edge Lane,Chorlton,M21
地理编码器获取的目的是为了返回邮政地址的坐标,您的字符串中没有足够的信息来返回准确的结果:
看起来它只是返回邮政编码的地理编码:
英国曼彻斯特M21 9JF(53.4414411,-2.285287100000005)
看起来地理编码器确实具有该位置。如果我使用圣克莱门特教堂,边缘巷,它似乎得到了屋顶地理编码(尽管它报告APPROXIMATE)
圣克莱门特教堂,6 Edge Ln,曼彻斯特,兰开夏郡M21 9JF,英国(53.4406823,-2.283755499999984)
代码段:
$ b
html,body,#map_canvas {height :100%;宽度:100%; margin:0px; < script src =https:// //maps.googleapis.com/maps/api/js?libraries=places\"></script><div id =map_canvas>< / div>
I have a database containing addresses that are accurate to building level. When I put these manually into Google Map's search, Google Maps finds them no problem - the markers appears right over the correct building. However, when I pass these same addresses to the Google Maps API geocoder using the below code, the markers show up only on the street and not the building.
How do I increase the accuracy?
HTML/PHP:
<div id="addressline"><?php echo theaddress(); ?></div>
JS:
function myGeocodeFirst() {
geocoder = new google.maps.Geocoder();
geocoder.geocode( {'address': document.getElementById("addressline").innerHTML},
function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
firstLoc = results[0].geometry.location;
map = new google.maps.Map(document.getElementById("map_canvas"),
{
center: firstLoc,
zoom: 15,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
markers = new google.maps.Marker({
position: firstLoc,
map: map,
});
}
else {
document.getElementById("text_status").value = status;
}
}
);
}
window.onload=myGeocodeFirst;
Google Maps uses a number of different data sources to locate search results on the map.
The entry you are seeing that is "correct" is a Places database entry. See this page and enter you search string (St Clement’s Church, Edge Lane, Chorlton, M21 9JF).
The geocoder gets is designed to return coordinates for postal addresses, there is not enough information in your string for it to return accurate results:
It looks like it is just returning the geocode for the postcode:
Manchester M21 9JF, UK (53.4414411, -2.285287100000005)
It does look like the geocoder does have that location in it. If I use "St Clement’s Church, Edge Lane", it seems to get the "rooftop" geocode (although it reports "APPROXIMATE")
St Clement's Church, 6 Edge Ln, Manchester, Lancashire M21 9JF, UK (53.4406823, -2.283755499999984)
code snippet:
var geocoder, map, service, infowindow, bounds;
function initialize() {
map = new google.maps.Map(
document.getElementById("map_canvas"), {
center: new google.maps.LatLng(37.4419, -122.1419),
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var request = {
query: "St Clement’s Church, Edge Lane, Chorlton, M21 9JF"
}
infowindow = new google.maps.InfoWindow();
service = new google.maps.places.PlacesService(map);
bounds = new google.maps.LatLngBounds();
service.textSearch(request, callback);
}
google.maps.event.addDomListener(window, "load", initialize);
function callback(results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
var place = results[i];
var marker = createMarker(results[i]);
bounds.extend(marker.getPosition())
}
map.fitBounds(bounds);
google.maps.event.trigger(marker, 'click');
}
}
function createMarker(place) {
var placeLoc = place.geometry.location;
var marker = new google.maps.Marker({
map: map,
position: place.geometry.location
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(place.name);
infowindow.open(map, this);
});
return marker;
}
html,
body,
#map_canvas {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px
}
<script src="https://maps.googleapis.com/maps/api/js?libraries=places"></script>
<div id="map_canvas"></div>
这篇关于谷歌地图地理编码器不如谷歌地图准确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!