How do I pass multiple parameter in URL?


url = new URL(""+lat+"&param2="+lon);

must work. For whatever strange reason1, you need ? before the first parameter and & before the following ones.

Using a compound parameter like

url = new URL(""+lat+"_"+lon);

would work, too, but is surely not nice. You can’t use a space there as it’s prohibited in an URL, but you could encode it as %20 or + (but this is even worse style).

1 Stating that ? separates the path and the parameters and that & separates parameters from each other does not explain anything about the reason. Some RFC says “use ? there and & there”, but I can’t see why they didn’t choose the same character.

Leave a Comment