Unable to display kml file in Google Maps V3 API

2,075 views
Skip to first unread message

Ching-wah Mok

unread,
Jan 3, 2011, 8:20:14 PM1/3/11
to google-map...@googlegroups.com
Can any Google Map experts tell me what is wrong to my code related the standard sample from Google Maps V3 (layer-kml.html)?
 
As I downloaded the related kml file (cta.kml) from gmaps-samples.googlecode.com into my local website virtual directory and change my code as follows, I was unable to find the geometry displayed in the related position.  However, alert shows that the KML had been loaded successfully.  Displaying this 'http://localhost/google/egis/geodata/cta.kml' in Google Earth application and plugin has no problems.  What have I missed to make it display in Google Maps?
 
Code:
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);      
// var ctaLayer = new google.maps.KmlLayer('http://gmaps-samples.googlecode.com/svn/trunk/ggeoxml/cta.kml'); 
var ctaLayer = new google.maps.KmlLayer('http://localhost/google/egis/geodata/cta.kml'); 
if (ctaLayer)
{
    ctaLayer.setMap(map);
    alert('ctaLayer is loaded.');
}
   else
{
       alert('ctaLayer is Null.');
}

James McGill

unread,
Jan 3, 2011, 8:42:02 PM1/3/11
to google-map...@googlegroups.com
Your KML file must be accessible on the public Internet - that is, it must be accessible to any machine which is connected to the internet. As a rule, http://localhost is not accessible to the public Internet - only to your local machine.

Regards,
James

Ching-wah Mok

unread,
Jan 3, 2011, 9:07:38 PM1/3/11
to google-map...@googlegroups.com
Dear James,
 
I tried to use http://wisdom /google/egis/geodata/cta.kml where wisdom is the local web service accessible by the Intranet, the geometries were not displayed.   However, I used google earth v2 api code as follow, it worked.
 
Code:
.......
 ge.getView().setAbstractView(la);
 google.earth.fetchKml(ge,'http://localhost/google/egis/geodata/cta.kml',finishFetchKml);
 }        
  
 function finishFetchKml(kmlObject)
 {               
  if (kmlObject)
  {
   ge.getFeatures().appendChild(kmlObject);     
  }
  else
  {
   alert(kmlObject + 'KML is not loaded');
  }
 }  

James McGill

unread,
Jan 3, 2011, 9:09:56 PM1/3/11
to google-map...@googlegroups.com
No, this is not sufficient. I cannot access http://wisdom from my machine, therefore it is not on the public Internet. I suggest uploading your file to a free web host (AppEngine or similar works for me)

Google Earth has different limitations to the Google Maps API.

Regards,
James

--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.

Ching-wah Mok

unread,
Jan 3, 2011, 9:22:24 PM1/3/11
to google-map...@googlegroups.com
Dear James,
 
Those KML files which I wanted to publish were corporate sensitive KML data are expected to be restricted to some user groups within the Intranet.  Then, it means that I cannot use this way to publish them to google maps V3 api.  Of course, my future plan is to deliver those kml files through web services, is there any other ways to read kml file for the google.maps.KmlLayer api function or other subroutines.
 
Regards
David
Message has been deleted

geoco...@gmail.com

unread,
Jan 3, 2011, 10:38:46 PM1/3/11
to Google Maps JavaScript API v3
You could try geoxml3:
http://code.google.com/p/geoxml3/

It allows access to local files (they _have_ to be in the same domain
as the requesting page currently).

Please note however that your map must be public to comply with the
Google Maps API terms of use, if it is hosted on an intranet you will
need to purchase a premier license:
http://code.google.com/apis/maps/documentation/premier/

-- Larry

>
> Regards
> David

dtipson

unread,
Jan 7, 2011, 1:14:22 PM1/7/11
to google-map...@googlegroups.com
Google displays your kml by you giving it a link to it, and then it makes it's OWN request to see the kml file, compresses it into a format usable on Google maps, and then feeds that information back onto the map you are using. If Google (or anyone else) doesn't have access to the file, it can't read it, and thus it can't display it.  Simple as that.
Reply all
Reply to author
Forward
0 new messages