Problems geocoding addresses with "#" for Apartment Number

2,968 views
Skip to first unread message

efg...@gmail.com

unread,
Jan 22, 2011, 3:48:31 PM1/22/11
to google-map...@googlegroups.com
Sorry if I missed this somewhere in the documentation.
 
Using the online geocoding example, I added "Apt 23" to the address:
 
This geocodes OK, but replaces "Apt" with # in the formatted address:
"formatted_address": "1600 Amphitheatre Pkwy #23, Mountain View, CA 94043, USA"
 
But if I attempt to geocode the address with the # for Apt.
 
that results in an error:
 
{
  "status": "REQUEST_DENIED",
  "results": [ ]
}      
 
Is there some rule I don't understand about "#" here?  Are there other special characters that should be avoided?
 
Thanks for any insight about this.

Michael Geary

unread,
Jan 22, 2011, 4:06:18 PM1/22/11
to google-map...@googlegroups.com
The # character has special meaning in a URL. Anything after the # is never sent to the server at all!

You need to run your address through encodeURIComponent() before putting it into the URL. For example:

var address = '1600 Amphitheatre Parkway #23, Mountain View, CA';

The resulting URL is now:


and that should work fine.

-Mike
--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.

JKurtock

unread,
Jan 23, 2011, 11:49:34 AM1/23/11
to Google Maps JavaScript API v3
There's another, more subtle issue. If you on rely location_type as a
measure of "quality" of the result, I found that it returns
"approximate" with the apartment number, when it would return
"rooftop" without the apartment number.
http://groups.google.com/group/google-maps-js-api-v3/browse_thread/thread/982173188110debb/32d4815a009896bc?lnk=gst&q=JKurtock+geocoder#32d4815a009896bc
In my use, I strip off the apartment number before sending it the
Geocoder (so that a location_type of "rooftop" or "approximate" is
meaningful).

If haven't tested this in a few months, Google often changes subtle
parts of the API, so running a test would be a good idea.


On Jan 22, 12:48 pm, efgl...@gmail.com wrote:
> Sorry if I missed this somewhere in the documentation.
>
> Using the online geocoding example, I added "Apt 23" to the address:http://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphith...
>
> This geocodes OK, but replaces "Apt" with # in the formatted address:
> "formatted_address": "1600 Amphitheatre Pkwy #23, Mountain View, CA 94043,
> USA"
>
> But if I attempt to geocode the address with the # for Apt.http://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphith...
Reply all
Reply to author
Forward
0 new messages