在网上(谷歌搜索)一段时间后,我找不到任何地址,例如:
1200 宾夕法尼亚大道 SE,华盛顿,哥伦比亚特区,20003
并将其转换为可点击的链接:
首选 jQuery 或 PHP 或任何有用的信息。
在网上(谷歌搜索)一段时间后,我找不到任何地址,例如:
1200 宾夕法尼亚大道 SE,华盛顿,哥伦比亚特区,20003
并将其转换为可点击的链接:
首选 jQuery 或 PHP 或任何有用的信息。
这个怎么样?
https://maps.google.com/?q=1200 Pennsylvania Ave SE,华盛顿,哥伦比亚特区,20003
https://maps.google.com/?q=term
如果您有经纬度,请使用以下网址
https://maps.google.com/?ll=latitude,longitude
示例:maps.google.com/ ?ll=38.882147,-76.99017
更新
截至 2017 年,谷歌现在有一种创建跨平台谷歌地图 URL 的官方方式:
https://developers.google.com/maps/documentation/urls/guide
您可以使用类似的链接
https://www.google.com/maps/search/?api=1&query=1200%20Pennsylvania%20Ave%20SE%2C%20Washington%2C%20District%20of%20Columbia%2C%2020003
我知道我参加比赛的时间很晚,但我想我会为后代做出贡献。
我编写了一个简短的 jQuery 函数,它会自动将任何<address>
标签转换为 Google 地图链接。
$(document).ready(function () {
//Convert address tags to google map links - Michael Jasper 2012
$('address').each(function () {
var link = "<a href='http://maps.google.com/maps?q=" + encodeURIComponent( $(this).text() ) + "' target='_blank'>" + $(this).text() + "</a>";
$(this).html(link);
});
});
我还遇到了需要从链接生成嵌入式地图的情况,尽管我会与未来的旅行者分享:
$(document).ready(function(){
$("address").each(function(){
var embed ="<iframe width='425' height='350' frameborder='0' scrolling='no' marginheight='0' marginwidth='0' src='https://maps.google.com/maps?&q="+ encodeURIComponent( $(this).text() ) +"&output=embed'></iframe>";
$(this).html(embed);
});
});
2016 年 2 月:
我需要根据客户端输入的数据库值来执行此操作,并且没有纬度/经度生成器。这些天谷歌真的很喜欢纬度/经度。这是我学到的:
1 链接的开头如下所示: https ://www.google.com/maps/place/
2 然后你输入你的地址:
3 把地址放在地址后面/
4 然后在最后加上一个斜线。
注意:最后的斜线很重要。用户点击链接后,Google 会继续在 URL 上附加更多内容,并在此斜杠之后执行此操作。
这个问题的工作示例:
https://www.google.ca/maps/place/1200+Pennsylvania+Ave+SE,+Washington,+DC+20003/
我希望这会有所帮助。
I had a similar issue where I needed to accomplish this for every address on the site (each wrapped in an address tag). This bit of jQuery worked for me. It'll grab each <address>
tag and wrap it in a google maps link with the address the tag contains contains!
$("address").each(function(){
var address = $(this).text().replace(/\,/g, '');
var url = address.replace(/\ /g, '%20');
$(this).wrap('<a href="http://maps.google.com/maps?q=' + url +'"></a>');
});
Working example --> https://jsfiddle.net/f3kx6mzz/1/
最好的方法是使用这条线:
var mapUrl = "http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=16900+North+Bay+Road,+Sunny+Isles+Beach,+FL+33160&aq=0&sll=37.0625,-95.677068&sspn=61.282355,146.513672&ie=UTF8&hq=&hnear=16900+North+Bay+Road,+Sunny+Isles+Beach,+FL+33160&spn=0.01628,0.025663&z=14&iwloc=A&output=embed"
记得在必要时替换第一个和第二个地址。
如果您有纬度和经度,您可以使用以下网址的任何部分或全部
https://www.google.com/maps/@LATITUDE,LONGITUDE,ZOOMNUMBERz?hl=LANGUAGE
例如: https ://www.google.com/maps/@31.839472,54.361167,18z?hl=en
借用 Michael Jasper 和 Jon Hendershot 的解决方案,我提供以下内容:
$('address').each(function() {
var text = $(this).text();
var q = $.trim(text).replace(/\r?\n/, ',').replace(/\s+/g, ' ');
var link = '<a href="http://maps.google.com/maps?q=' + encodeURIComponent(q) + '" target="_blank"></a>';
return $(this).wrapInner(link);
});
与以前提供的解决方案相比,该解决方案具有以下优势:
<br>
标记)<address>
,因此保留格式<a><address></address></a>
,因为<address>
诸如<a>
.警告:如果您的标签包含类似or<address>
的块级元素,则此 JavaScript 代码将生成无效标记(因为标签将包含这些块级元素)。但如果你只是在做这样的事情:<p>
<div>
<a>
<address>
The White House
<br>
1600 Pennsylvania Ave NW
<br>
Washington, D.C. 20500
</address>
然后它会工作得很好。
在http://www.labnol.org/internet/tools/short-urls-for-google-maps/6604/上,它们显示了一个运行良好的短 URL
谷歌地图 URL 非常笨拙,尤其是在通过 IM、推文或电子邮件发送时。MapOf.it 为您提供了一种快速链接到 Google 地图的方法,只需将位置地址指定为搜索参数即可。
我将它用于我设计的一些应用程序,它就像一个魅力。
http://maps.google.com/maps?q=<?php echo urlencode($address); ?>
编码你的转换器并添加所有额外的元素,如空格和所有。因此您可以轻松地从数据库中获取平面文本代码并使用它,而无需担心要添加的特殊字符
我刚找到这个并喜欢分享..
此外,任何想要手动对地址进行 URLENCODE 的人:http ://code.google.com/apis/maps/documentation/webservices/index.html#BuildingURLs
您可以使用它来创建符合 GM 标准的特定规则。
C# Replace 方法通常对我有用:
foo = "http://maps.google.com/?q=" + address.Text.Replace(" ","+");