Domanda

Trying to validate the following HTML with the W3C validator will throw 3 errors (as of 2013-10-30):

<!DOCTYPE html>
<head><title>asdf</title></head>
<img src="http://maps.googleapis.com/maps/api/staticmap?zoom=13&size=279x183&markers=50.916780,5.347420&sensor=false" alt="map">

The 3 errors are all the same:

& did not start a character reference. (& probably should have been escaped as &.)

Unfortunately, conforming to the W3C here will lead to the static maps image not being rendered. Try to embed an img tag with the following URL as the value for its src attribute:

<img src="http://maps.googleapis.com/maps/api/staticmap?zoom=13&amp;size=279x183&amp;markers=50.916780,5.347420&amp;sensor=false">

This returns an error by Google stating:

The Google Maps API server rejected your request. Invalid request. Missing the 'size' parameter.

Why does the Google Static Maps API not support valid URLs with &amp; in query string?

È stato utile?

Soluzione

You escaped the & characters correctly.

Note that you can’t enter the URI with escaped ampersands directly into the address bar of your browser. It only works if used in HTML (i.e. in href and src attributes).

The URL in question works perfectly as link (and also as image).


Note that you probably don’t have to escape these ampersands (as they seem to be unambiguous); but to be always on the safe side, simply escape them all.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top