Convert coordinates to be useable
I have a data source with coordinates in the following format.
N642500,W0241600
N660700,W0240000
N652000,W0222700
N660800,W0195500
S645500,E0170800
S644000,E0162200
I do not know what开发者_开发百科 format these are in or how to get these into a format I can use. This can either be JavaScript or PHP!
Looks like latitude, longitude in degrees, minutes, seconds (DMS). See http://www.ngs.noaa.gov/PC_PROD/Inv_Fwd/readme.htm for conversions.
Typically map applications will take the latitude and longitude in decimal form, so you would need to convert DMS to decimal (N is +, S is -). That said, I was somewhat surprised to find that Google maps will take DMS directly - see http://groups.google.com/group/Google-Maps-API/msg/670c54481d91e6b3?pli=1. So you don't even need to convert it. For example:
51 57' 32.48",00 55' 55.23"
http://maps.google.com/maps?f=q&hl=en&q=51++57%27+32.48%22,00+55%27+5...
If you need to compute it:
function DMS(lat,latm,lats,lon,lonm,lons) {
if (lat<0) {
latm = -latm;
lats = -lats;
}
if (lon<0) {
lonm = -lonm;
lons = -lons;
}
lat = lat + latm/60 + lats/3600;
lon = lon + lonm/60 + lons/3600;
return new GLatLng(lat,lon);
}
map.setCenter( DMS(35,3,39.08, -118,9,2.20));
Per http://groups.google.com/group/google-maps-api/msg/2e3436f3bf7d6155. But I think the API should take it directly.
Those would be latitude and longitude. The documentation of the data source should tell you what the units are; usually they're degrees (in various fractional forms), but you'll need to know whether the numbers given are decimal fractions of degrees, or degrees, minutes, and seconds.
In terms of converting them to useful numbers, that will depend on whether they're fractional degrees or degrees, minutes, and seconds; and what you want to use them for.
The format appears to be comma-separated values (CSV)
The values look like latitude (North + or South -) and longitude (West + or East -) followed by ddmmss
I think ddmmss is more likely than decimal degrees since the MM and SS digits are less than 59
-EDIT-
The values for LONGITUDE have to be +/- 180 (DDDMMSS) but the values for LATITUDE need to be +/- 90 (DDMMSS)
this js function will clean your string into an known lat lon format, usage example:
clean('N51618017,W0248291');
pretty simple, so here is the function
function clean(string){
var values = string.split(','),
lat,
lon;
if(values[0].search(/S/)){
lat = '-';
}
if(values[1].search(/W/)){
lon = '-';
}
lat += values[0].substring(1, 3)+'.'+values[0].substring(4);
lon += values[1].substring(1, 3)+'.'+values[1].substring(4);
//now you got your values
//so can do this:
var url = 'http://www.gorissen.info/Pierre/maps/googleMapLocation.php?lat='+lat+'&lon='+lon+'&setLatLon=Set';
//or just return them as an object:
pos = {name:'your pos name',latitude:lat,longitude:lon}
}
精彩评论