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

宾夕法尼亚大街东南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是首选或者任何有用的信息。


这个怎么样?

https://maps.google.com/?q=1200宾夕法尼亚大道,华盛顿,哥伦比亚特区,20003

https://maps.google.com/?q=term

如果你有latong然后使用下面的URL

https://maps.google.com/?ll=latitude,longitude

例子:maps.google.com/ ?噢= 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 

在http://www.labnol.org/internet/tools/short-urls-for-google-maps/6604/上,他们显示了一个简短的URL,工作得很好

地图url是相当笨拙的,特别是在发送即时消息,推特或电子邮件时。MapOf。它为您提供了一个快速的方法来链接到谷歌地图,只需指定位置的地址作为搜索参数。

http://mapof.it/

我在自己设计的几个应用程序中使用了它,效果非常好。

另外,任何想要手动URLENCODE地址的人:http://code.google.com/apis/maps/documentation/webservices/index.html#BuildingURLs

您可以使用它来创建满足GM标准的特定规则。

我知道我来得太晚了,但我想为了子孙后代,我应该有所贡献。

我写了一个简短的jQuery函数,将自动将任何<地址>标记转换为谷歌地图链接。

点击这里查看演示。

$(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?&amp;q="+ encodeURIComponent( $(this).text() ) +"&amp;output=embed'></iframe>";
        $(this).html(embed);             
    });
});

那么这个呢: http://support.google.com/maps/bin/answer.py?hl=en&answer=72644

最好的方法是这样说:

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"

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

你可以看看工作样本

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

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

c#的Replace方法通常适用于我:

foo = "http://maps.google.com/?q=" + address.Text.Replace(" ","+");

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

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

我有一个类似的问题,我需要为站点上的每个地址(每个地址都包装在一个地址标签中)完成此操作。这一点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/

借鉴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);
});

与以前提供的解决方案相比,该解决方案具有以下优点:

它不会删除<address>内的HTML标记(例如<br>标记),因此格式被保留 它正确地编码URL 它压缩了多余的空格,以便在编码后生成的URL更短、更干净、更易于阅读 它产生了有效的标记(Mr.Hendershot的解决方案创建了<a><address></address></a>,这是无效的,因为<address>这样的块级元素在<a>这样的内联元素中是不允许的。

注意:如果<address>标记包含块级元素,如<p>或<div>,则此JavaScript代码将生成无效标记(因为<a>标记将包含这些块级元素)。但如果你只是做这样的事情:

<address>
  The White House
  <br>
  1600 Pennsylvania Ave NW
  <br>
  Washington, D.C.  20500
</address>

那就没问题了。

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

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.

2016年2月,:

我需要这样做基于客户端输入的数据库值,没有一个长/长生成器。谷歌最近很喜欢拉特/长。以下是我所学到的:

1 链接的开头是这样的: https://www.google.com/maps/place/

2 然后写上你的地址:

用“+”代替任何空格。 在城市的前面和后面加上逗号。 包括邮政/邮编和省/州。 将任何#替换为空。 将任意++或++++替换为单个+

3. 把地址放在“/”后面

4 然后在最后加上斜杠。

注意:结尾的斜杠很重要。在用户单击链接后,谷歌继续执行并向URL追加更多内容,并且在这个斜杠之后执行。

这个问题的工作示例:

https://www.google.ca/maps/place/1200+Pennsylvania+Ave+SE,+Washington,+DC+20003/

我希望这对你有所帮助。

如果你有纬度和经度,你可以使用波纹URL的任何部分或全部

https://www.google.com/maps/@LATITUDE,LONGITUDE,ZOOMNUMBERz?hl=LANGUAGE

例如: https://www.google.com/maps/@31.839472,54.361167,18z?hl=en