Why won’t my basic KML file show a map of Japan?
June 30, 2007 12:14 AM   Subscribe

I recently bought “Google Maps Applications with PHP and AJAX” and am already having a problem with the first chapter. Going over KML files and how they can be used to mark certain areas on a Google Map, the book gives an example of multiple points in Toronto. I followed the same example to try and mark a point in Yokosuka, Japan. When I view the Toronto example, it works fine. When I try my Yokosuka example, it just displays a point marker on a blank grey background; the map never loads.

I’ve tried both the Toronto KML file and my Yokosuka KML file on my server, and only Toronto works. I've checked the coordinates by manually searching for them in GMaps and Yokosuka comes up fine.

Here’s my KML file (also found here):

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.google.com/earth/kml/2">
<Document>
<name>yokosuka.kml</name>
<Placemark>
<name>Yokosuka Japan</name>
<description>
This is my first KML file. Insert some random crap about Yokosuka.
</description>
<Point>
<coordinates>35.277647,139.665585</coordinates>
</Point>
</Placemark>
</Document>
</kml>

As you can see, it doesn’t show anything but a point with no map. You can see the Toronto example works though. here.

Am I doing something wrong? Is there something wrong with GMaps in foreign countries? I really don’t want to give up this book after the first chapter, so please help me out here.

Thanks!
posted by jimdanger to Computers & Internet (6 answers total)
 
From here, I'm guessing your second line (namespace definition) needs to be something like:

<kml xmlns="http://earth.google.com/kml/2.1">
posted by paulsc at 12:58 AM on June 30, 2007


Response by poster: @paulsc: I made a copy of the original file with the suggested change, but I get the same result.
posted by jimdanger at 2:29 AM on June 30, 2007


OK, thats just weird.

Your coordinates match those given for Yokosuka in Google Earth but in your file they take you to the middle of the ocean.

If you change them to -35.277647,139.665585 the kml file takes you to just off the coast of Japan.
posted by demagnetized at 4:49 AM on June 30, 2007


Response by poster: That's why I was wondering if GMaps had issues with Japan. If that's the case, is there a workaround?
posted by jimdanger at 5:09 AM on June 30, 2007


Best answer: Your cordinates are backwards.

If you look at the yahoo geocode response for Toronto (using yahoo because it can be accessed on the web without a special key :p)
<ResultSet xsi:schemaLocation="urn:yahoo:maps http://api.local.yahoo.com/MapsService/V1/GeocodeResponse.xsd">

<Result precision="zip">
<Latitude>43.648565</Latitude>
<Longitude>-79.385329</Longitude>
<Address/>
<City>Toronto</City>
<State>ON</State>
<Zip/>
<Country>CA</Country>
</Result>
</ResultSet>
If you compare that with your Toronto KML file - the coordinate are entered in the order Longitude, Latitude

There are a buch of entries for Yokusa so these coords may not be an exact match for yours but they're close enough:

<Result precision="zip">
<Latitude>35.260159</Latitude>
<Longitude>139.661758</Longitude>
<Address/>
<City>yokosuka-shi</City>
<State>Japan</State>
<Zip/>
<Country>JP</Country>
</Result>

which would make your coordinates 139.66, 35.26 approx but you have them the other way around.

As a point of interest if you were using point = new GLatLng() the coordinates would be 35, 139 (approx) not the other way around.

Dont ask me why but I stumbled into this problem on a few days ago - I requested coordinates from googles geocode service and it gave me 7.010593,43.550871, 0 as a coordinate response, but to use them as coords for a googlemap point they should be 43.550871, 7.010593
posted by missmagenta at 5:13 AM on June 30, 2007


Response by poster: missmagenta: That worked! That's strange that it's backwards, but now I know. Thanks so much.
posted by jimdanger at 5:25 AM on June 30, 2007


« Older ipod attacks human   |   Copyrights on web & software projects Newer »
This thread is closed to new comments.