Reputation: 841
I currently have the task of integrating some GPS data stored in a MySQL database with google earth. The objective is to create placemarks/waypoints of these readings and display them on google earth.
I googled the task and came across an article : "A Database Driven Earth App: Using PHP & MySQL with the Earth API" .
Located at the URL:
https://developers.google.com/earth/articles/phpsqlearth
I followed it successfully; until I came to where I had to create the placemarks. The main issue is that the 'createPlacemark' function has the following signature:
"createPlacemark(name,address,type,lat,lng)" .
My main point of concern is the lat
and lng
arguments (latitude and longitude), because the GPS data in the
database are all in the format :
"N5 bb.xxx E8 cc.yyy".
No separate longitude or latitude data was stored. The data is being collected via a garmin gps. I was thinking that perhaps I could resolve this issue by doing this:
var point = ge.createPoint('N5 bb.xxx E8 cc.yyy ') ,
and forget about the
point.setLatitude(parseFloat(lat))
and
point.setLongitude(parseFloat(lng)) statements.
However , I wanted to confirm if I was on the right path seeing I will be away from my development machine for a few days.
Upvotes: 2
Views: 245
Reputation: 17094
No, calling the GEPlugin method createPoint
like you have it
var point = ge.createPoint('N5 bb.xxx E8 cc.yyy');
would create a point with the ID N5 bb.xxx E8 cc.yyy
- the createPoint
method only takes a single string parameter and that is used to set the ID
of the object.
As you have it the resultant point KML would look like this:
<Point id="N5 bb.xxx E8 cc.yyy">
</Point>
You would need to call one or more methods on the actual point object that is created to set the latitude and longitude data. Either point.set()
or point.setLatitude()
and point.setLongitude()
- you would then finally set the point to the placemarks geometry for it to work.
looking at it all you really need to do is to parse the Garmin GPS using a simple function. Simply splitting the string using white-space should work fine.
//parse a string in the Garmin format "N5 bb.xxx E8 cc.yyy"
//returns a kmlpoint
function gpsToPoint(data) {
var parts = data.split(' ');
var point = ge.createPoint('');
point.setLatitude(parseFloat(parts[1]));
point.setLongitude(parseFloat(parts[3]));
return point;
}
Then just change the createPlacemark function so that you create the point object with the new gpsToPoint()
method passing in the the Garmin data.
This would give you KML like
<Point>
<coordinates>bb.xxx,cc.yyy,0</coordinates>
</Point>
Upvotes: 1