简体   繁体   中英

How to handle '#' in url for google maps

I am doing integration of google maps with my website for mobile. Whenever i pass an address to the url which contains '#', it shows the address before the occurance of '#'

Example: if the address is test1#test2 and i pass it to the google url, in the map it shows test1.

URL i am using is "http://maps.google.com/maps?daddr=" + add" where add is the variable

A hash (#) is a specific token in a URI (a/k/a URL). It means that you're looking for part of a page and not a whole resource. Typically, when you need to include a token that would cause issues in parsing a URL (such as a "$" or a "/"), you should "URI-encode" the token. This results in something like %20 (a space), or %2F ("/"). You probably just need to URI-encode your hash as %23 .

Chances are you should be URI-encoding the entire address you want to send, not just hashes. There are many options for doing this. JavaScript even has a built-in function that does the job ( encodeURIComponent() ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM