13

Is there any way I can use a KMZ file in Google Maps? My KML file is around 10.7MB so it doesn't load on Google Maps. KMZ file is around 2MB. The only way I see it is to have multiple KML but it's too much work. I might end up doing that, but was just wondering if KMZ can be used?

Thanks.

kaoscify
  • 1,743
  • 7
  • 37
  • 74

2 Answers2

19

Yes, you can specify a KMZ file using the Maps API:

var kmzLayer = new google.maps.KmlLayer('http://www.kmzlinks.com/redirect.asp?id=110&file=PalmIsland%2Ekmz');
kmzLayer.setMap(map);

In your specific case, your script should look like this:

<script type="text/javascript">
  function initialize() {
    var myOptions = {
      center: new google.maps.LatLng(58.33, -98.52),
      zoom: 11,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    var kmzLayer = new google.maps.KmlLayer('http://xeenat.com/energy/data.kmz');
    kmzLayer.setMap(map);
  }
</script>

BUT - your KML is too big. Even though it's compressed down to 2MB as a KMZ, Maps looks at the size after it's been decompressed, and in your case that's bigger than 10MB. Try cutting it down a bit - if you replace your KMZ URL with the one in the first snippet above, it will work. Looks like you'll need to use multiple KML files. Perhaps you could load the KMZ into Google Earth, then save each province as its own file (right-click on the folder in Earth's "Places" tab, and select Save as...)

Mike Jeffrey
  • 3,149
  • 1
  • 19
  • 18
  • in your code, map isn't declared as a global variable, so when you call it, it comes up with an exception: Uncaught ReferenceError: map is not defined. You need to put var map; before function initialize() { – Mano Marks Mar 21 '12 at 18:47
  • Looks like KMZ won't help in this case - there's still a size restriction on the uncompressed KML from the KMZ: https://developers.google.com/kml/documentation/mapsSupport – Mike Jeffrey Mar 21 '12 at 18:52
  • 1
    @MikeJeffrey I'm very new to JavaScript, and I have done what you said but now my map isn't loading. I actually got that whole code snippet from the Google Maps v3 documentation. – kaoscify Mar 21 '12 at 18:54
  • @ManoMarks 2.58MB is the size of my KMZ file. Should be okay? – kaoscify Mar 21 '12 at 18:55
  • 1
    Edited my answer to include specific info. – Mike Jeffrey Mar 21 '12 at 19:25
  • Great! Glad I could help :) Please accept the answer by clicking the checkmark if you feel it's correct. – Mike Jeffrey Mar 21 '12 at 20:10
2

Yes, you can specify a KMZ file the exact same way you would specify a KML file you can even set both at the same time notice how nothing changes except for the variable name and file extension:

var kmz_Layer = new google.maps.KmlLayer('http://www.kmzlinks.com/redirect.asp?id=110&file=PalmIsland%2Ekmz');
var kml_Layer = new google.maps.KmlLayer('http://www.kmzlinks.com/redirect.asp?id=110&file=PalmIsland%2Ekml');
kml_Layer.setMap(map);
kmz_Layer.setMap(map);
rhodesit
  • 41
  • 8