在网上搜索了一段时间后,我找不到任何像这样的地址:

宾夕法尼亚大街东南1200号 华盛顿,哥伦比亚特区,20003年

并将其转换为可点击的链接:

http://maps.google.com/maps?f=q&source=s_q&hl=en&q=1200+Pennsylvania+Ave+SE,+Washington,+District+of+Columbia,+20003&sll=37.0625,-95.677068&sspn=44.118686,114.169922&ie=UTF8&cd=1&geocode=FT5MUQIdIDlp-w&split=0&ll=38.882147,-76.99017&spn=0.01064,0.027874&z=16&iwloc=A

jQuery或PHP是首选或者任何有用的信息。


当前回答

我有一个类似的问题,我需要为站点上的每个地址(每个地址都包装在一个地址标签中)完成此操作。这一点jQuery对我有用。它会抓取每个<address>标签,并将其包装在一个谷歌映射链接中,其中包含标签所包含的地址!

$("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>');

}); 

工作示例——> https://jsfiddle.net/f3kx6mzz/1/

其他回答

这是我从谷歌地图的一篇文章中发现的:

Open Google Maps. Make sure the map or Street View image you'd like to embed shows up on the map. In the top left corner, click the main menu ​☰. Click Share or embed map. At the top of the box that appears, choose the Embed map tab. Choose the size you want, then copy the code and paste it into the source code of your website or blog. Note: If you're using Maps in Lite mode, you won't be able to embed a map. Keep in mind that traffic information and some other Maps info might not be available in the embedded map.

我刚发现这个,喜欢分享。

在maps.google.com上搜索你的地址 点击右下角的齿轮图标 点击“共享或嵌入地图” 单击短url复选框,并将结果粘贴在href..

http://maps.google.com/maps?q=<?php echo urlencode($address); ?> 

encode ur conver并添加所有额外的元素,如for空格和all。所以你可以很容易地从db中获取平面文本代码并使用它,而不用担心要添加的特殊字符

最好的方法是这样说:

var mapUrl = "http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=16900+North+Bay+Road,+Sunny+Isles+Beach,+FL+33160&amp;aq=0&amp;sll=37.0625,-95.677068&amp;sspn=61.282355,146.513672&amp;ie=UTF8&amp;hq=&amp;hnear=16900+North+Bay+Road,+Sunny+Isles+Beach,+FL+33160&amp;spn=0.01628,0.025663&amp;z=14&amp;iwloc=A&amp;output=embed"

记得在必要时替换第一和第二个地址。

你可以看看工作样本

我有一个类似的问题,我需要为站点上的每个地址(每个地址都包装在一个地址标签中)完成此操作。这一点jQuery对我有用。它会抓取每个<address>标签,并将其包装在一个谷歌映射链接中,其中包含标签所包含的地址!

$("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>');

}); 

工作示例——> https://jsfiddle.net/f3kx6mzz/1/