After looking (Googling) on the web for a while, I can find nothing that takes an address like:
1200 Pennsylvania Ave SE, Washington, District of Columb
Also, anyone wanting to manually URLENCODE the address: http://code.google.com/apis/maps/documentation/webservices/index.html#BuildingURLs
You can use that to create specific rules that meet GM standards.
Borrowing from Michael Jasper's and Jon Hendershot's solutions, I offer the following:
$('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);
});
This solution offers the following benefits over solutions previously offered:
<br>
tags) within <address>
, so formatting is preserved<a><address></address></a>
which is invalid because block-level elements such as <address>
are not permitted within inline elements such as <a>
.Caveat: If your <address>
tag contains block-level elements like <p>
or <div>
, then this JavaScript code will produce in invalid markup (because the <a>
tag will contain those block-level elements). But if you're just doing stuff like this:
<address>
The White House
<br>
1600 Pennsylvania Ave NW
<br>
Washington, D.C. 20500
</address>
Then it'll work just fine.
The C# Replace method usually works for me:
foo = "http://maps.google.com/?q=" + address.Text.Replace(" ","+");
If you have latitude and longitude, you can use any part or all of bellow URL
https://www.google.com/maps/@LATITUDE,LONGITUDE,ZOOMNUMBERz?hl=LANGUAGE
For example: https://www.google.com/maps/@31.839472,54.361167,18z?hl=en
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/
This is what I found from one of the Google Maps articles:
- 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.