Attention! Do you have any ideas for reorganizing and updating the Mapki? Please leave a note here. Thank you!

FAQs

From Google Mapki

Jump to: navigation, search

For more information about using the Google Maps and the Google Maps API, see the Knowledge Base.

Contents

These are issues that have been brought up many times on the Google Groups discussion list. The FAQ consists of frequently asked questions and their answers. To obtain answers to specific or uncommon questions, please post on the Google Maps API group.

[edit] Read This First

A short list of issues that are encountered very frequently:

Read This First

[edit] Getting Started

A more advanced Google/Yahoo! map page generator that helps you add default locations, find a starting lat/lon position, add controls. Does not help you add your Key. MapBuilder.net has been featured by Import functionality to import and geocode addresses from CSV file. Also MapBuilder.net has Europe/Asia coverage (GMaps APIv2) and draggable markers support!
  • Wizard for any non-techie to create their own map (another API)
(is this the right link? - this does not look like a Wizard, it looks very technical - AB)
Use only HTML to create a map. This is NOT recommended for people who want to learn to hack their map. Good simple examples and explinations of how it works are on the page.
  • The $60 virtual training course Google Maps For Your Apps! is a computer-based training course. This course is designed to enable you to take advantage of Google Maps for your website. You will learn how to create maps, add map controls for user interactions (zooming, and panning), programmatically alter the map extent, add points of interest to the map, add custom icons, geocode addresses on the fly, read addresses from a database or XML file, and display aerial photography.
  • The book Google Maps API -- Adding Where to Your Applications is a quick and easy way to get started with the API. It offers everything from a simple "Hello World" example all the way up to creating custom GMarkers and using the AJAX interface to geocode your data from third-party sources. See Mapmap.org for live examples.
  • Click2Map is an editor for building visually your Google Maps. No programming is required. It also adds a lot new cool features to your maps.
  • MapLib
An advanced tool to help you turn any pictures into custom Google Maps, no complex knowledge required with simple steps. Embedding the generated maps in your web pages is allowed.

[edit] Browser Problems

  • Japanese IE problem
The Japanese version of Internet Explorer contains extra "entities", and when it sees &v=1&key=ABCDEFG it thinks you've missed the ";" off the ends of the entities "&v;" or "&key;" and tries to be helpful by inserting them and converting the entities to Japanese ideograms. The proper way to correct this is to encode the ampersand itself. Replace & with & followed immediately by amp;. Note that you should also use this encoding when using ampersands anywhere else in (X)HTML as well.
  • My map works in Firefox but not in IE!
A common cause of such failures is that Firefox tolerates the placement of Javascript within tables and other containers although it's technically illegal. IE enforces the rules more strictly, and throws an unhelpful error.
  • My map works in Firefox but I get "Operation Aborted" errors in IE!
These errors are produced in IE when the javascript tries to change the page before it has completed rendering. There are 3 common ways to solve this problem:
  1. move all the javascript to the <head> of the document and call a makeMap() function which initializes the Google Map in the onload handler (in the <body> tag, <body onload="makeMap();">). The onload handler is executed after the page finishes loading. thread1 thread2
  2. put all the javascript at the end of the <body> (just before the </body> tag) see this message.
  3. a variation of #1, use a setTimeout to delay the processing of the map code until the page has finished rendering. see this message.
  4. (variation of 1) use window.onload. Allows multiple onload handlers, see Doug Henderson's page at multiple onload handlers. This is the way that was used to fix the operation aborted error on the Get_Lon_Lat page here.
  • My map works in IE but not in Firefox!
This can be caused by the fact that Firefox has more reserved words than IE. You can't use 'long' as a variable name or 'onload' as a function name. Instead, try 'lng' and 'onLoad'.
  • My map page only displays 'Code corrupted. Insert fresh copy.'
Check to make sure that all of your JavaScript HTML elements have ending tags to match the beginning tags.
  • The map doesn't display, only a gray area.
  1. This can be caused by the security settings in the browser. Check that the browser allows images from other sources than the originating web site. If Firefox check in the menu Tools:Options:Load Images:For the originating website only, and check that there are no "google" entries in the "Exceptions" box.
  2. The 'gray' image you see could mean that you're in the middle of the Atlantic, Pacific or Indian oceans (just below Ghana or above Antarctica). The Latitude and Longitude values are empty, or swapped.
  3. If the problem persists, then something might be blocking your access to the images. This might be in your router or your proxy, or you might even be being blocked by Google if they think you're running an automated script that grabs huge numbers of map tiles. You can test for all these situations by pointing your browser directly at an individual Map Tile or Satellite Image tile. This allows the browser to display any error messages associated with the individual image.
  • My map works in Firefox but not in IE!
Check the characters being returned in your XML, particularly in descriptive text destined for marker popups, and even more particularly if the text originated in MS Word. The XML dom in IE seems to be far more fussy than Firefox.

[edit] Key Issues

  • Where do I get a Key?
Get a key for your map here. You must create or have a Google account.
  • Do I Need A Different Key for Different Websites?
Yes. You need a different Google Maps API key for each web site. You don't need a different Google account for that though. You can get as many keys as you want with the same Google account.
  • Can I get a key for local development?
You can just drag your html file into your browser. When the URL begins with "file:", the key checking is skipped.
If you want to test interaction with a server script, you can use Apache (or some other web server) on your computer and connect to it with http://localhost/. You would then apply for a key to http://localhost/ and use it like any other page. If you're running windows, read this great Apache for Windows install guide. Alternatively you can use a pre-packaged installer such as WAMPserver.
Note that if you want to use the GGeoXml object, the web page that you use to construct the GGeoXml must be publicly accessible. This is presumably because Google needs to do some processing on the server for the magic to work.
  • Error: The Google Maps API key used on this web site was registered for a different web site.
  • You need a separate API key for aliasses of your site. You can work round this either by having two keys and using the one that corresponds with the called location, or by having the main page call a frame using a hard-coded complete URL. An exception to this is that "www.mysite.com" now uses the same key as "mysite.com".
  • The "path" part of a URL associated with the API key is case specific, so "www.mysite.com/MAPS/" would need a different key from "www.mysite.com/maps/". Either ensure that your callers use the correct case, or have the main page call a frame using a hard-coded complete URL.
  • That error can also be generated by the pre-release beta version of IE 7, which isn't yet working correctly with Google maps.
  • Internationalised Domain Names
Punycode A method for coping with the situation where your host name contains non-ascii characters.

[edit] Map Data

  • How old are the satellite images?
Google uses various sources for the satellite imagery. The primary sources for the mosaicked satellite images:
  • DigitalGlobe - high (0.6-meter) resolution images of select areas taken since 2002
  • MDA EarthSat - medium (15-meter) resolution global satellite image mosaic derived from Landsat-7 scenes taken in 1999-2001
  • Where are some places to get data for my maps?
Check out the sources on the wiki Data Sources page.
  • I'm trying to fetch an XML file using XMLHttpRequest but the responseXML attribute contains no data...
The server is supplying the wrong Content-type for the file (probably text/plain). It's best to fix this on the server by placing the following directive in the .htaccess file for your directory (this assumes you are using Apache)
AddType text/xml .xml .xsl

It would be even better to have the server admin make the fix in the main configuration file. If you cannot make the change on the server, you can parse the responseText attribute with GXml.parse.
If you are generating the XML dynamically, you will need to add the correct Content-type header to your output.
Alternately, an intermittent failure of your XML to load may simply indicate a slow response from your hosting server.

[edit] Geocoding

  • Google now allows its API users to perform geocoding!!!
Yes! The Google Maps API does allow you to geocode. Learn more.
Geocoder.us offers both free (throttled @ 1 request/second) and fee based geocoding. Uses US Census Tiger data
Uses the Geocoder.us interface and the TigerLine 2005 FE files, more up to date than geocoder.us.
Free batch geocoding using Yahoo's REST Geocoding interface, run batches up to 500 address at a time. Makes use of NAVTEQ and Tele Atlas datasets.
Result uses USCensus Tiger data, bulk processes 10 or 200 addresses at a time. There are four ways to submit your addresses to the service:
1. Paste a list into a form box and it kicks back lat/lon values. US only as of Sept2205.
2. Automate the process by submitting addresses using a HTTP GET request. The site returns a CSV file. Here are the instructions on how to set it up.
3. Automate the process with a SOAP API call. Here are the instructions on how to set it up.
4. Include Javascript in HTML, to make calls directly from the browser. Here are the instructions on how to set it up.
Geocode America is a fast and accurate geocoding service based on the US Census Tiger data. There are SOAP, Rest, and web APIs for use. Examples in .NET, Java, and even Ruby. Free for non-commerical web access, otherwise very affordable rates
  • Beta Quality Geocoder by nearby.org.uk includes coordinate conversion mainly for UK but handles US zip codes
Andrew Bidochko features Geo!Suggest tool, an AJAX interface for the Yahoo! Geocoding API. He's also made the source code of GeoSuggest available for public use.


International geocoding

Outside the USA there are few free or cheap geocoding services.

For single point geocode's the best resource may be the Wikipedia. Nearly any place large enough to be in the Wikipedia also has its Lat/Long and a link to geocode the location.

In Canada there is Geocoder.ca.

In the UK, there is a service which will provide locations for sector postcodes and US zip codes nearby.org.uk.

Geonames.org has free postal code based geocoding for various countries.

There are services which will return the locations of towns and districts for the whole world, but they tend to be rather slow and don't provide an automated interface.

NGA GNS GEOnet Names Server. Getty TGN Thesausrus of Geographic Names.

There are lists of possibly useful resources for individual countries GEOnames links and ASU links.

You can also geocode international addresses by scraping Maporama.

The CIA World Fact Book also lists Coordinates for countries.

[edit] User Interface

  • How do I set the default map type so that when the map starts, it doesn't go straight to the street map?
Use the follow bit of code:
map.setMapType(G_HYBRID_TYPE);
  • My map is not in the right location on the page.
If your map displays in the wrong place on the screen, the id="map" used to identify your map div may not be unique. The browser is putting the map in the other container with the same "id" or the same "name".
  • Undocumented Features
Useful Undocumented Features that can be used, but might possibly change or disappear with a future release of the API code.
  • How do I generate a sidepanel?
See thread1 thread2 Basic Tutorial
  • How do I get the keyboard to work?
How to get the keyboard to work
  • How do I display filled polygons?
There are several ways to display filled polygons on Google Maps:
    • GPolygon class is now supported and documented. As of V2.69 (1/17/2007). See http://www.google.com/apis/maps/documentation/reference.html#GPolygon and http://googlemapsapi.blogspot.com/
    • The following are presumably depreciated.
    • Use the undocumented (and presumably unsupported) GPolygon class. See http://www.geocities.com/goldnbr1/gmap/gpolygonsample.html for an example that uses GPolygon.
    • Create custom tiles. Custom tiles are good when you have a lot of polygons. It's a lot of work to create the tiles, but once they are done, it's quite snappy. See Webfoot Maps for an example.
    • Use a KML overlay. (KML is the "native language" for overlays on Google Earth.) Create a KML file and enter its URL into a Google Maps box. For example, paste this URL into a Google Maps query box: http://www.juiceanalytics.com/downloads/ca_co_pd.kmz. KML files are good if you have a small number of polygons and you want to look at them yourself (not share with others). There is a 1M limit on the size of the uncompressed KML file; KML files are not currently integrated with the API.
    • Use the EInsert extension. This works well for a small number of polygons; more than 40 or so, and the performance will degrade.
    • Use the "Filled Polygons" extension. This is only good for a very small number of polygons, as the polygons are filled by drawing polylines back and forth across the shape with polylines. It is therefore really slow in browsers that don't support VML or SVG.
    • Use a third-party library for polygons:

[edit] Data I/O

The errors "xmlDoc has no properties" may indicate slow server response or incorrect server MIME type setting. "documentElement is null or not an object" is usually caused by your server setting the wrong MIME type on your XML data file. If you can't change your server to set the MIME type to "text/xml" you can change your code to use "var xmlDoc = GXml.parse(request.responseText);" instead of "var xmlDoc = request.responseXML;". Also, an ampersand ('&') in the xml file may cause the xml file to behave as if it has no contents when trying to be read by the Google Map.

[edit] Markers

Internet Explorer will not cache the marker's images until they are full loaded, so if you create hundreds of markers on a row, Internet Explorer will ask hundreds of times for the same image to the server. You should add your marker's images to the body of your html page for the image to be fully loaded before javascript code starts running. For instance, if your image is marker_foo.png, add <img src="marker_foo.png" style="display:none">. You should also preload the shadow image. You can see all the gory details at this link.
  • Marker Optimization Tips
    • Only Draw the Points in the Area Viewport
    • Load Different Points at Different Zooms
    • Add HTML to InfoWindows(Bubble) Using Click Event
    • Use GMarkerManager (new in v2.67) efficiently
  • Marker Clustering
Jef Poskanzer has produced "Clusterer.js" which can cluster the markers in reasonably large data sets without server side scripting or database. Clusterer page Mike's Tutorial Example dating site using clusters with thousands of entries
You should not link directly to images! Please download and host on your own server.
If you want to constantly update the position of a marker, for example marking a moving vehicle, it's faster to move an existing marker than to add a new one.
Markers and other Google images used in the maps.
This tutorial shows you how you can add tooltips to your markers, just like those on Google Local.

[edit] Implementing/Extending Google Map API Features

  • Why does my map stops working when I change the map type?
Make sure that your latitude and longitude are floats and not strings. Use parseFloat(lat) to fix it. The Google code can go into a loop trying to animate a pan movement. It moves the map by a distance of "Not a Number" in each frame of the animation, and the pan animation never completes.
  • How can I put driving directions on my map?
thread1 thread2 another example another by linking 'from:' and 'to:' query string example
  • IFrame workaround
  • How do I specify the height/width of an InfoWindow?
thread1
  • How can I draw a circle?
thread1 thread2 thread3 Fast Circles
  • How do I create an infoWindow that contains both text/html and a blowup map?
thread1 An example
  • How do I add my own custom map?
See Add Your Own Custom Map; the Automatic Tile Cutter is highly useful when making your own map. You might also find the GmapUploader useful -- see Kyle Mulka's [blog posting.
  • How do I put one map on top of another and let the user change the transparency level of the top map?
Overlay A Transparent Map
  • How do I add custom map controls?
A quick and dirty way to implement your own custom controls is to place your own control icons at absolute locations on top of the map using styles. Like this: <img src="zoomout.png" onclick="zoomout()" style="top:100px; left:25px; position:absolute; z-index:99">. Note that PNG transparency won't work in IE for icons placed like this, so make your icons square or use GIFs.
  • How do I add tabs to my info windows, like Google Local sometimes has?
Tabbed Infowindows

[edit] Permissions

  • Permission to use Google Maps API outside the Terms of Use, e.g. to use it on an Intranet or in a desktop application.
You are permitted to use Google Maps on an Intranet, or in a desktop application only if you buy Google Maps for Enterprise. Prices start at $10,000 per year and it is only available in a few countries.
  • Permission to use the maps in printed publications
You can request permission to use Google Maps imagery in printed publications by using the Request For Permission to Use Google Brand Features.
I know that seems unlikely, but that's the word from Google in This post

[edit] Map Rotation

  • Is it possible to rotate the map (so that north isn't straight up)?
It isn't easy to do that with the current API, but the folks at Flash Earth managed to pull it off. http://www.flashearth.com/

[edit] Polygon Intersection

  • How do I figure out if two polygons intersect?
That depends in part on what tools you are using.

Also note that John Coryat posted a technique that you could use to significantly reduce the number of polygons that you need to look at.

[edit] Other Information

You can't use usenet, but you can do this
The U.S. Postal Service does not publish the boundaries of ZIP codes as such. (The USPS doesn't seem to think of ZIP codes in terms of areas, but rather as a collection of points.) The U.S. Census Bureau publishes approximations to the ZIP codes as Zip Code Tabulation Areas (ZCTAs), which might be accurate enough for your purposes. John Coryat at http://maps.huge.info is a consultant who is probably the world expert on ZIP code boundaries (and he didn't pay me to write that, either); you might try contacting him.
Retrieved from "http://mapki.com/wiki/FAQs"
Personal tools
Advertisement