400 errors when requesting dynamic maps markers

193 views
Skip to first unread message

Jesse Fulton

unread,
Jul 30, 2009, 1:12:55 PM7/30/09
to Google Chart API
First of all, thanks a ton for exposing the functionality to
dynamically create markers for Google Maps.

I've followed the directions at http://groups.google.com/group/google-chart-api/web/chart-types-for-map-pins
for creating dynamic, custom pins. But when running my site locally on
http://localhost/, I get 400 errors (bad request) about 90% of the
time when requesting those images from a page, whether it be via
JavaScript using a custom GIcon, or via a CSS background image. (See
"shadow maps" comments at
http://mapscripting.com/create-dynamic-numbered-markers-for-google-maps/comment-page-1#comment-216)

If I add an entry in my hosts file and hit the site via
http://localhost.mydomain.com/, I get the same error (although, I also
get an error from the API because I haven't registered that domain
with my API key yet...)

BUT, if I hit my local site as http://localhost.google.com/ everything
works perfectly!

Are there limits on referrers and how frequently you can hit the API?
Are any IPs or domains being blocked? It'd be really helpful to get
this consistently working across all of my environments.

Thanks,
-Jesse

KeithB

unread,
Jul 30, 2009, 1:33:48 PM7/30/09
to Google Chart API
Requesting Google Maps resources with your specific Google Maps API
key should have nothing to do with getting "400 Bad Reqeust" errors on
your Google Chart API calls. The Maps API validates your key before
returning its resources and, separately, the Chart API sends back its
response. Does your individual Chart API calls return valid images
when you put them in the address bar of a browser? I ask because in
the past I've had a few malformed Chart URLs that would work sometimes
and not work at other times (400 Bad Request errors). It seemed pretty
random, but it ended up being issues with my URL parameters. I'd
double check the syntax of each and every parameter, making sure you
haven't doubled up on anything (multiple CHM parameters, etc.).

Hopefully that will help. Good luck,
K

KeithB

unread,
Jul 30, 2009, 1:42:01 PM7/30/09
to Google Chart API
While my above advice may help people with Chart URL issues, you're
absolutely right about http://www.google.com/chart? calls not working
on localhost or localhost:port.

I'll look into this more later...

Good luck,
K

Jesse Fulton

unread,
Jul 30, 2009, 1:50:04 PM7/30/09
to Google Chart API
Yep, the URLs work fine if I hit them directly in my browser (FF
3.0.12, Win XP)

The weird thing is that I have an entry in my hosts file so that
http://localhost.google.com/ points to 127.0.0.1 (localhost.) If I hit
the page as http://localhost.google.com/map everything works fine
without touching any code. If I hit the page as http://localhost/map
(again, not changing any code or server settings), it doesn't work.

Here is a sample of what the CSS code looks like:
------
.destination-1 {list-style-image: url("http://www.google.com/chart?
chst=d_map_pin_letter&chld=1|00CCFF|000000"); }
.destination-2 {list-style-image: url("http://www.google.com/chart?
chst=d_map_pin_letter&chld=2|00CCFF|000000"); }
.destination-3 {list-style-image: url("http://www.google.com/chart?
chst=d_map_pin_letter&chld=3|00CCFF|000000"); }
.destination-4 {list-style-image: url("http://www.google.com/chart?
chst=d_map_pin_letter&chld=4|00CCFF|000000"); }
.destination-5 {list-style-image: url("http://www.google.com/chart?
chst=d_map_pin_letter&chld=5|00CCFF|000000"); }
-----

And here is a sample of what the JS code looks like:
-----
//this is inside of an init() method...

var markers = [];

for (var i=0; i<mapData.length; i++) {
var item = mapData[i];

var lat = item["latitude"];
var lng = item["longitude"];

var opts = {"icon": "http://www.google.com/chart?
chst=d_map_pin_letter&chld="+(i+1)+"|00CCFF|000000"};

markers.push(new Marker(new GLatLng(lat, lng), opts));
}

markerManager.addMarkers(markers, 0);
-----

Watching the requests, the JS code appears to be correct. It generates
URLs like: http://www.google.com/chart?chst=d_map_pin_letter&chld=3|FFCCFF|000000.
Again, when I watch the requests coming from the page, i get 400
error, but when I hit the URL directly, it works perfectly.

Jesse Fulton

unread,
Sep 2, 2009, 6:28:06 PM9/2/09
to Google Chart API
Hey Keith,

Any chance you've been able to look into this further?

Thanks,
-Jesse

On Jul 30, 10:50 am, Jesse Fulton <jesseful...@gmail.com> wrote:
> Yep, the URLs work fine if I hit them directly in my browser (FF
> 3.0.12, Win XP)
>
> The weird thing is that I have an entry in my hosts file so thathttp://localhost.google.com/points to 127.0.0.1 (localhost.) If I hit
> the page ashttp://localhost.google.com/mapeverything works fine
> without touching any code. If I hit the page ashttp://localhost/map

KeithB

unread,
Sep 2, 2009, 7:09:15 PM9/2/09
to Google Chart API
Sorry, I assumed that you'd see the recent posts by Roger regarding
using "chart.apis.google.com/chart" instead of the "www.google.com/
chart". My quick test shows that making that change should fix your
localhost usage issues.

Cheers,
K
Reply all
Reply to author
Forward
0 new messages