谷歌地图显示的位置名称,如果找到,否则只是地址 [英] Google map to show name of location if found, otherwise just the address

查看:356
本文介绍了谷歌地图显示的位置名称,如果找到,否则只是地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在我的网站上使用嵌入的Google地图来显示找到的位置的名称,如果找不到,那么只需填写地址?



我可以让我的代码在所有情况下显示地址,但名称仅在某些情况下才显示。我在 http://www.yankeedesi.com/testmap.htm 中有几个例子。如果你看第一行,我可以得到地图与地址一起工作,但不能与地名一起工作。在第二行,但是这两种情况都起作用。





我使用的第一个代码是:

 < iframe width = 300height =250frameborder =0style =border:0
src =https://www.google.com/maps/embed/v1/place?key=<MyKey> &安培; q = 910 + 11 + ST,阿纳科特斯+ WA + 98221\" >
< / iframe>

,第二个是

 < iframe width =300height =250frameborder =0style =border:0
src =https://www.google.com / maps / embed / v1 / place?
key = AIzaSyCpmbSHS59rVuyJGtIStR4CcGo2g3dNXF8
& q = Little + Calcutta + Restaurants,910 + 11th + St,Anacortes + WA + 98221>
< / iframe>

现在在第二种情况下,Google地图无法找到名称为Little + Calcutta +餐馆,它不搜索地址。



我想要的是:
如果名称搜索成功,然后显示它的名称,否则搜索与地址并忽略名称。是否有可能?

解决方案

是的,使用geocoder



var geocoder;



在制作地图之前将其添加到您的初始化中

< geocoder = new google.maps.Geocoder();

 函数搜索(){
var address = document.getElementById('address')。value;

geocoder.geocode({'address':address},function(results ,状态){
if(status == google.maps.GeocoderStatus.OK){
//搜索完成
}其他{
//再次搜索,但子字符串您的地址
}


Can I use embedded Google map in my website to show the name of location if found, and if not found then just the address?

I can get my code to show the address in all cases but the name is showing up only in some cases. I have a few examples in http://www.yankeedesi.com/testmap.htm. If you look at the first row, I can get the map working with address but not with name of the place. In the second row, however both the cases are working.

The code I used for the first one is:

<iframe width="300" height="250" frameborder="0" style="border:0"
 src="https://www.google.com/maps/embed/v1/place?key=<MyKey>&q=910+11th+St,Anacortes+WA+98221">    
</iframe>

and for the second one is

<iframe width="300" height="250" frameborder="0" style="border:0" 
src="https://www.google.com/maps/embed/v1/place?
key=AIzaSyCpmbSHS59rVuyJGtIStR4CcGo2g3dNXF8
&q=Little+Calcutta+Restaurants,910+11th+St,Anacortes+WA+98221">
</iframe>

Now in the second case because Google map is unable to find the address with the name Little+Calcutta+Restaurants, it is not searching the address as well.

What I want is: If the search with name is successful then show it with name, else search with address and ignore the name. Is that possible?

解决方案

yeah use geocoder

var geocoder;

add this to your initialize before making a map

geocoder = new google.maps.Geocoder();

function search(){
 var address = document.getElementById('address').value;

geocoder.geocode( { 'address': address}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { //search complete } else { //search again but subtring your address }

这篇关于谷歌地图显示的位置名称,如果找到,否则只是地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆