Reputation: 189
I am trying to draw a line between two coordinates on Google Maps. The two coordinates I wish to use are:
4738.3319,N, 01903.2312,E,
4738.3219,N, 01903.7575,E,
I have converted these as follows:
47.383319, 19.032312
47.383219, 19.037575
I am using the code below:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Simple Polylines</title>
<style>
html, body, #map-canvas {
height: 100%;
margin: 0px;
padding: 0px
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
<script>
// This example creates a 2-pixel-wide red polyline showing
// the path of William Kingsford Smith's first trans-Pacific flight between
// Oakland, CA, and Brisbane, Australia.
function initialize() {
var mapOptions = {
zoom: 12,
center: new google.maps.LatLng(47.383219, 19.037575),
mapTypeId: google.maps.MapTypeId.TERRAIN
};
var map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
var flightPlanCoordinates = [
new google.maps.LatLng(47.383319, 19.032312),
new google.maps.LatLng(47.383219, 19.037575),
];
var flightPath = new google.maps.Polyline({
path: flightPlanCoordinates,
geodesic: true,
strokeColor: '#FF0000',
strokeOpacity: 1.0,
strokeWeight: 3
});
flightPath.setMap(map);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map-canvas"></div>
</body>
</html>
My problem is, that Google Maps draws the line somewhere on the southern border of Budapest, when they should point roughly to the norther border. Also, the longitude is almost good, it has a smaller inaccuracy (about 2 km), but latitude is absolutely wrong. I need at least a 15-20 meters accuracy. Am I using a wrong format?
Upvotes: 0
Views: 121
Reputation: 6293
Your coordinates are probably in a format where the first digits are degrees, the two digits before dot are minutes, and those after the dot are fractions of minutes. That is,
4738.3319,N, 01903.2312,E
means 47 degrees 38.3319 minutes north and 19 degrees 3.2312 minutes east.
To convert these to decimal degrees that are suitable for Google maps, you need to divide the minutes by 60 (as there are 60 minutes per degree), not 100. This gives you
47 + 38.3319/60 = 47.638865 N, 19 + 3.2312/60 = 19.053853 E
which is, indeed, on the northern side of Budapest.
Upvotes: 1