GPolygon Example

Wednesday, January 24, 2007 at 10:11:00 AM



Hi all, my name's Pamela Fox. I've just joined the Maps API team and will be working part-time on various projects until I finish my Masters in C.S. at USC and join full-time. I'm looking forward to making GMaps easier to work with for developers and first-timers.

To start off my time here, I've made a simple example showing off what you can do with the recently documented GPolygon. Even if you're not the type of person who enjoys a good square, pentagon, or googolgon, you can also use this class to generate stars and "circles" with only slight changes in code. The example below lets you click on the map to generate either squares, circles, or polygons of random color, size, and sides (for polygons/stars). Play around with it - Trust me, it's fun!

Here's how it works:

  • We define several utility functions to aid in generating random numbers and colors
  • When the map is clicked, we find the clicked pixel using fromLatLngToPixel on the result of G_NORMAL_MAP.getProjection().
  • We start generating random variables for small radius, large radius (used for stars), number of sides, and color.
  • If the draw mode selected is polygon, we iterate from 0 to number of sides. In each iteration, we calculate the new pixel location using good old trigonometry. We convert the pixel back to latitude/longitude using fromPixelToLatLng and add it to our points array.
  • If the draw mode selected is a star or circle, the process is almost the same. For stars, we iterate twice as much as the number of sides, calculating points at the large radius on the odd iterations. For circles, we ignore the randomly generated number of sides and always iterate 20 times around the clicked pixel for a nice round look.
  • Now for the magic - we create a new GPolygon with the points array and style parameters, and add it to the map.
  • Now here's the challenge: my own example is pretty useless, except for its teaching value. How can you put GPolygon to work for your app? Exploit the GPolygon for all it's worth (and don't forget its friend, GPolyline), and ping us with your creations on the forums.

Googolgon, Anyone?

Wednesday, January 17, 2007 at 9:25:00 AM



Some of you have probably noticed that we've added a new tool to your Google Maps API toolbox, the GPolygon. Just think of all the colorful triangles, octagons, hendecagons, icosagons, etc. that you'll be able to overlay on your map. I'll be really impressed if someone is able to build a googolgon, a polygon with 10100 sides.

More details about the GPolygon class can be found in the Maps API reference.

New Map Tiles for India, Singapore, and Hong Kong Added to the Google Maps API

Thursday, January 11, 2007 at 2:45:00 PM



Some of you may have noticed that we recently added new map tiles for India, Singapore, and Hong Kong to the sites served by the Google Maps API. For India, these new map tiles cover all the major cities (with a combined population of more than a 100 million). This data includes the national highway network, major and minor arterial roads, local roads in all metros, railway lines, railway stations, tourist attractions, educational institutes, places of worship, historical landmarks, hotels, movie theaters, malls, shopping centers, etc. We feel that this data provides tremendous service to our users as high quality map data has not been commonly available for free in India. While we don't yet support full address search or business search in India, we know users want this, and we are working hard to get it to them as soon as possible. Till then, everyone can search for any city within India.

Here's an example of the new map tiles, as shown on WikiMapia.

We are very excited that all of this new data is now accessible from the Google Maps API. We welcome you to create applications that will revolutionize your communities. And as always, if you see any bugs in the new maps, please let us know.

Drive More Traffic to Your Maps API Site - Include KML Files in Your Sitemap

Monday, January 08, 2007 at 9:37:00 AM



Your Google Maps API powered site has lots of great content. Including KML files in a sitemap.xml file (see http://www.sitemaps.org/protocol.html ) is a great way for you to help us index and drive traffic to your site. After publishing your data in KML, we'll crawl the KML files that you specify in your sitemap.xml file. We'll send users your way when they search for content that is found on your mashup site. As an added bonus, once your data is in KML, it will be available for viewing on Google Earth.

Publishing a KML Sitemap involves a few easy steps:

  • Identify those features on your maps site which can be displayed as KML features.
  • Convert those features into KML equivalents and publish them within one or more KML files.
  • Create a sitemap.xml file that identifies links to all of your KML files.
  • Place the sitemap.xml in the root directory of your site.
Please see our sitemap documentation ( http://www.google.com/apis/maps/sitemap.html) for more details about including your KML content in a sitemap.