Welcome to WebmasterWorld Guest from 54.80.115.140

Forum Moderators: open

Message Too Old, No Replies

KML - recomendations on how to get coordinates

     
11:52 pm on Jan 7, 2008 (gmt 0)

Full Member

10+ Year Member

joined:Apr 30, 2006
posts: 298
votes: 0


I've recently gotten some projects making KML documents for use in google maps/earth. I've scoured the web for a couple days looking for a good way to get longitude/latitude coordinates easily, but can't find any.

The KML specificationi requires this:

<coordinates>-82.539107,35.560781,0</coordinates>

But the google earth browser only shows coordinates like this (a completely different system):

34 2'19.75"N
7430'26.57"W

In google earth, there is a way to "create a point" and then essentially bring up the source code and then hunt for the coordinates amid a bunch of other junk. Slow and ugly.

I'm looking for some kind of service that I can right-click on a map, and choose "copy coordinates", and have that put "-82.539107,35.560781", into my clipboard. Anything like this exist anywhere?

2:19 am on Jan 8, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 21, 2005
posts: 1526
votes: 0


It sounds like a question that might be better asked of the Google Groups [groups.google.com]. It's more of a user thing than an XML thing.

I use KML files all the time (I do a lot with Google Maps), but I have found that there are no decent KML editors out there. Google Earth is okay, but is basically "write only." You can't read KML files and change them, which drives me nuts.

I just use Google Earth to create a KML file, then use those points.

4:27 am on Jan 8, 2008 (gmt 0)

Full Member

10+ Year Member

joined:Apr 30, 2006
posts: 298
votes: 0


Thanks for the idea, but I've learned to post to multiple forums at the same time. I posted to the KML google group first, but as of yet, no response. That post is here, [groups.google.com]in case anyone is interested.

In my case, I'll be needing to make kml docs on the fly from a database, and thought someone here might have experience getting coordinates easily. Seems like some mapping system would have this available, or something even better that I haven't thought of. I've even looked for a FFox extension, but no luck.

Anyway, trying never hurt anyone...

So cmarshal: what is your method of making kml, just author it in GEarth? Then is there some export tool?

GEarth has specific guidlines as to what can be done (commercially) with KML authored in GE.

6:48 am on Jan 8, 2008 (gmt 0)

Preferred Member

10+ Year Member

joined:Feb 10, 2006
posts:627
votes: 0


not sure if this will help you much...

g provides service where you can enter address and it will give you coordinates of the place, along with status code (ex. 200 = ok) and value on the scale from 1-10 which stands for how confident g is that the address is at coordinates given
query looks something like this:

http://maps.google.com/maps/geo?q=street town state zipcoe&output=csv&key=your_googlr_maps_key

output looks for above query which asked for results to be delivered in cvs format ( from above: "...output=csv...") looks like

200,8,37.376688,-122.200624

you can change output from cvs to xml or kml and it will deliver it in that format. Perhaps you can programmaticaly (spl?) query g's system and import xml/kml results for your needs

8:43 am on Jan 8, 2008 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:11236
votes: 126


i have a map creation form where i use a google map to navigate to a location and scale and it "dynamically" loads the coordinates and scale into the appropriate form input fields.

something like this for the javascript:

<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=[your GOOGLE_MAPS_KEY]" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
function load() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.addControl(new GLargeMapControl());
map.addControl(new GScaleControl());
map.setCenter(new GLatLng(38,-95,4);
GEvent.addListener(map, "move", function() {
var latitude = [however you want to find your map LATITUDE form input parameter by id or name];
var longitude = [however you want to find your map LONGITUDE form input parameter by id or name];
var scale = [however you want to find your map SCALE form input parameter by id or name];
var ctrpoint = map.getCenter();
latitude.value = ctrpoint.lat();
longitude.value = ctrpoint.lng();
scale.value = map.getZoom();
});
}
}
//]]>
</script>

and then the html looks like:

<div id="map" style="width: 800px; height: 420px"></div>

(plus the three form input fields of course)

(NOTE:u.s.-centric map and div size settings)

11:25 am on Jan 8, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 21, 2005
posts: 1526
votes: 0


So cmarshal: what is your method of making kml, just author it in GEarth? Then is there some export tool?

GEarth has specific guidlines as to what can be done (commercially) with KML authored in GE.

There is that. I do NPO sites that won't run afoul of any Google TOS, so I don't worry too much about it.

I don't know if I have much more advice. However, I'd love to hear about it if you find a decent tool.

I do know that you can licen$e Google Earth for commercial use.

11:47 am on Jan 8, 2008 (gmt 0)

Full Member

10+ Year Member

joined:Feb 4, 2004
posts:305
votes: 0


I have a few googlemaps on my site and for one of them I made a special editmode that I use to find the coordinates of clicked locations.
In case of the editmode the following HTML is added right below the map:

<form name="centerform">
<table id="mapedit" border=0 cellspacing=2 cellpadding=2>
<tr>
<td width=340><div>Mouse Coordinates: <span id="mousepoint"></span></div></td>
<td width=340>Latitude [,Longitude]: <input type="text" name="lat" value="0" size="25"></td>
</tr>
<tr>
<td><div>Center Coordinates: <span id="mapcenter"></span>&nbsp;&nbsp;&nbsp;<a href="#" onclick="MarkCenter(); return false;">Mark</a></div></td>
<td>Longitude [,Latitude]: <input type="text" name="lng" value="0" size="25"></td>
</tr>
<tr>
<td><div>Clicked Coordinates: <span id="clickpoint"></span></div></td>
<td><div style="float:left">Zoom level: <span id="zoomlevel"></span></div>
<div style="float:right"><a href="#" onclick="PanToCoord(document.centerform.lat.value, document.centerform.lng.value); return false;">Center Map</a></div></td>
</tr>
</table>
</form>

The following javascript is used when the map is created and add some listeners to the map (variable is called TheMap in my case):

UpdateCenter();
GEvent.addListener(TheMap,"click",function(editmarker,editpoint){
if(editmarker){TheMap.removeOverlay(editmarker);
}else{
TheMap.addOverlay(new GMarker(editpoint));
document.getElementById("clickpoint").innerHTML=LimitCoordStr(editpoint);
}
});
GEvent.addListener(TheMap,"mousemove",function(point){document.getElementById("mousepoint").innerHTML=LimitCoordStr(point);});
GEvent.addListener(TheMap,"load",function(){document.getElementById("mapcenter").innerHTML=LimitCoordStr(TheMap.getCenter());});
GEvent.addListener(TheMap,"move",UpdateCenter);

And below the javascript to handle the events:

function UpdateCenter(){
document.getElementById("mapcenter").innerHTML=LimitCoordStr(TheMap.getCenter());
document.getElementById("zoomlevel").innerHTML=TheMap.getZoom();
}
function LimitCoordStr(Point){
var NrDecimals=5;
var Lat=1.0*Point.lat();
var Lon=1.0*Point.lng();
var NewCoordStr=Lat.toFixed(NrDecimals)+', '+Lon.toFixed(NrDecimals);
return NewCoordStr;
}
function PanToCoord(Lat,Lon){
var LocalLat,LocalLon,SplitPos;
Lat=Lat.replace(new RegExp(/\s+/)," ");
Lon=Lon.replace(new RegExp(/\s+/)," ");
if((Lat.indexOf(",")> 0)(Lat.indexOf(" ")>=0)){
SplitPos=Lat.indexOf(",");
if(SplitPos<=0)SplitPos=Lat.indexOf(" ");
LocalLat=Lat.slice(0,SplitPos);
LocalLon=Lat.slice(SplitPos+1);
}else
if((Lon.indexOf(",")>=0)(Lon.indexOf(" ")>=0)){
SplitPos=Lon.indexOf(",");
if(SplitPos<=0)SplitPos=Lon.indexOf(" ");
LocalLon=Lon.slice(0,SplitPos);
LocalLat=Lon.slice(SplitPos+1);
}else{
LocalLat=Lat;LocalLon=Lon;
}
TheMap.panTo(new GLatLng(LocalLat,LocalLon));
document.getElementById("mapcenter").innerHTML=LimitCoordStr(TheMap.getCenter());
}
function MarkCenter(){
TheMap.addOverlay(new GMarker(TheMap.getCenter()));
document.getElementById("clickpoint").innerHTML=LimitCoordStr(TheMap.getCenter());
}

When the mouse hovers over the map it will display the current mouse position in latitude,longitude. Also the map center is displayed and when clicked on the map a marker will appear and its position will also be displayed below the map.
Furthermore it is possible to enter latitude and longitude values and center the map to that position.
12:00 pm on Jan 8, 2008 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:11236
votes: 126


i forgot to add that you can certainly take that google maps code and modify it to do some clipboard magic for you instead of valuating form input fields.
in this case you would use a different event, such as:
GEvent.addListener(map, "singlerightclick", function(point) {
// use pixel location of right click, transform to decimal map coordinates, convert to comma-separated string
var latlongstring = map.fromContainerPixelToLatLng(point).toUrlValue();
// and then find some javascript to put that string in your clipboard
});
2:54 pm on Jan 8, 2008 (gmt 0)

Full Member

10+ Year Member

joined:Apr 30, 2006
posts: 298
votes: 0


There seems to be some good stuff in these lasts posts. It's early yet in the day, but I'll come back to these and give them a go. But wanted to thank all posters and any new info, of course, is still appreciated.

BML

4:32 pm on Jan 8, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 21, 2005
posts: 1526
votes: 0


Just FYI. I scared up a bit of code to show coordinates:

<div id="map" style="width: 500px; height: 400px"></div>
<br />
<div id="log" style="width: 500px; height: 200px; border: 1px solid black; padding:4px; overflow:scroll"></div>
<!-- This is a "localhost" key. It might work for you. -->
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAABCC8PsaKPPEsC3k649kYPRTENGtRdzMzwmQVY1i9K4XasOqh2RSLyLFhET6KTJd7EsAY3yaOuCC_Bg" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
window.onload = function load_goo() {
if (GBrowserIsCompatible()) {
var point = new GLatLng(40.78,-73.97);
var map = new GMap2(document.getElementById("map"));
map.addControl(new GLargeMapControl());
map.addControl(new GScaleControl());
map.setCenter(point, 12);
marker = new GMarker(point, {draggable: true, title: "Drag to a New Location, or Click for More Info."});
GEvent.addListener(marker, "dragend", function() {
var ctrpoint = map.getCenter();
var latitude = ctrpoint.lat();
var longitude = ctrpoint.lng();
var scale = map.getZoom();
var str = 'latitude = '+latitude+', longitude = '+longitude+', scale = '+scale;
document.getElementById("log").innerHTML += str+"<br />";
} );
map.addOverlay(marker);
}
}
//]]>
</script>
6:10 pm on Jan 8, 2008 (gmt 0)

Senior Member from CA 

WebmasterWorld Senior Member httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Aug 29, 2003
posts:4061
votes: 0


pixeltierra, i don't know of any system like what you describe

I was doing a lot of geo-data entry in 2006; I had painstakingly built an enormous KML (actually several split KML files) with about 10,000 places in it. To make the data entry more manageable, I created a PHP script that parsed the KML and inserted the places into SQL. There, they were much easier to sort, select, etc

That solves the "Slow and ugly" problem

It actually became fun, overlaying historical maps onto Google Earth, nudging them to match terrestrial landmarks, then tracing where all the ancient places once were. The KML parser removed all the pain

7:56 pm on Jan 8, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 21, 2005
posts: 1526
votes: 0


Oops. Made a boo-boo (guess no one really wanted to give it a go, eh?)

I want to use this as part of a general-purpose tool, so I may actually develop the code a bit more.

<div id="map" style="width: 500px; height: 400px"></div>
<div id="log" style="width: 500px; height: 200px; margin-top:8px; border: 1px solid black; padding:4px; overflow:scroll"></div>
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAABCC8PsaKPPEsC3k649kYPRTENGtRdzMzwmQVY1i9K4XasOqh2RSLyLFhET6KTJd7EsAY3yaOuCC_Bg" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
window.onload = function load_goo() {
if (GBrowserIsCompatible()) {
var point = new GLatLng(40.78,-73.97);
var map = new GMap2(document.getElementById("map"));
map.addControl(new GLargeMapControl());
map.addControl(new GScaleControl());
map.setCenter(point, 12);
marker = new GMarker(point, {draggable: true, title: "Drag to a New Location."});
GEvent.addListener(marker, "dragend", function() {
var ctrpoint = marker.getLatLng();
var latitude = ctrpoint.lat();
var longitude = ctrpoint.lng();
var scale = map.getZoom();
var str = 'latitude = '+latitude+', longitude = '+longitude+', scale = '+scale;
document.getElementById("log").innerHTML += str+"<br />";
} );
map.addOverlay(marker);
}
}
//]]>
</script>
9:33 pm on Jan 8, 2008 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:11236
votes: 126


cmarshall:

you should examplify your google maps api key...

10:08 pm on Jan 8, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 21, 2005
posts: 1526
votes: 0


Actually, it's a "localhost" key.

I figured it wouldn't hurt to leave it in.