user220755
user220755

Reputation: 4446

Coloring a map depending on information (using google maps api or another api)

I am trying to build an application that will use an Api like google maps api (or any other api for maps) in order to color the states depending on some information that change. So for example, let's say I am going to color states green if they have more than 5 people online and this information will change every minute, how can i use some maps api in order to color the states using javascript, php, and other web development languages but not flash?

If you need more explanation please let me know and i will edit the post to include more information.

This is (NOT) a homework question so please provide as much information and code as possible.

Thanks!

Upvotes: 0

Views: 834

Answers (2)

npdoty
npdoty

Reputation: 4757

For something very simple, you might try using the Google Chart API, which can create map visualizations highlighting different countries in the world or different states in the United States. The API is extremely simple: you just construct a special URL and Google will return a static image constructed based on your particular data; you can just put the URL as the src attribute of an img tag. (Of course, because it's a static image, it doesn't have any of the interactive functionality of Google Maps.)

Re-loading an image every minute shouldn't be too difficult using Javascript/jQuery. You might even be able to re-load the same URL each time and have your server return a re-direct header for the appropriate updated Google Chart API image URL. (I'm not sure whether browser caching could interfere with that, though, you might want to add a random parameter to the image request each time.)

Upvotes: 0

TheSteve0
TheSteve0

Reputation: 3526

The google map api allows you to change the color of the polygon in your code. You would need to have the geometries of the states so you can draw them as a layer on top of google maps

I would say have your PHP script generate a new KML file every interval. Here is an example of using KML directly in the google API http://code.google.com/apis/maps/documentation/examples/geoxml-kml.html

Found under the service examples here: http://code.google.com/apis/maps/documentation/examples/index.html

I am sure there is probably a KML library in PHO.

You would just do an ajax call on a timer and re-pull KML at the interval you would like. Clear the map after pulling and then re-draw the new KML.

Upvotes: 1

Related Questions