Welcome to WebmasterWorld Guest from 3.84.243.246
Forum Moderators: open
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
74°30'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?
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.
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.
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
something like this for the javascript:
<script src="http://maps.google.com/maps?file=api&v=2&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)
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.
<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> <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>
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);
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());
}
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
});
<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&v=2&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>
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
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&v=2&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>