meinsm
Goto Top

GoogleMaps mit Gauß-Krüger

Hallo,

ich habe die GoogleMaps Api-v3 auf einer Webseite integriert.
Unter anderem stelle ich damit eine KML-Datei dar.
Und ich stelle eine Adresse mit
   geocoder.geocode({
      'address': address  
   }, 
dar.
Das funktioniert auch.
Jedoch möchte ich das ganze jetzt ohne Adresse und dafür mit Koordinaten im Gauß-Krüger-Format machen.

Ist das möglich? Und wie kann ich das umsetzen?

Vielen Dank schon mal im Voraus für die Unterstützung.

Content-Key: 326194

Url: https://administrator.de/contentid/326194

Printed on: April 25, 2024 at 14:04 o'clock

Member: Kraemer
Kraemer Jan 12, 2017 at 15:21:48 (UTC)
Goto Top
Moin,

klick

Gruß Krämer
Member: meinsm
meinsm Jan 13, 2017 at 07:26:56 (UTC)
Goto Top
Danke für den Link.
Aber soweit ich das richtig verstehe, funktioniert das nur mit Longitude/Latitude, oder?
Kann ich das irgendwie umrechnen?
Member: Kraemer
Kraemer Jan 13, 2017 at 08:02:10 (UTC)
Goto Top
Klar kann man das umrechnen. Dazu musst du aber exakt wissen, was für ein Ausgangsmaterial du hast.
siehe u.a. hier

Den Rest kannst du dir dann bitte selbst zusammen googlen.

Gruß Krämer
Member: colinardo
Solution colinardo Jan 13, 2017, updated at Jan 16, 2017 at 12:40:40 (UTC)
Goto Top
Servus meinsm,
hier ein einfaches Beispiel um Gauß-Krüger in Dezimalgrad umzurechnen und es dem Geocoder zu übergeben.
(Google API-Key anpassen).
<!doctype html>
<html>
<head>
<meta charset="utf-8">  
<title>Google Geocoder</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>  
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"></script>  
<script type="text/javascript">  
function GetLocationFromGK(){
	var geocoder = new google.maps.Geocoder();
	var gk = $('#txtAdresse').val().split(',');  
	var decimal_result = GK_To_Decimal(parseFloat(gk.trim()),parseFloat(gk[1].trim()));
	geocoder.geocode({ 'location': decimal_result }, function (results, status) {  
	if (status == google.maps.GeocoderStatus.OK) {
		var koordinaten = new google.maps.LatLng(results.geometry.location.lat(), results.geometry.location.lng());
		$('#coords').text(koordinaten + " / " + results[1].formatted_address);  
	} else {
		$('#coords').text("Fehler: " + status);  
	}
	});
}

function GK_To_Decimal(rw, hw)	{ 
	// Rechtswert rw und Hochwert hw im Potsdam Datum
	   var ll = {}; 
	   if (rw == "" || hw == "" || isNaN(rw) || isNaN(hw)) return ll;  
	   
	   rw = parseFloat(rw);
	   hw = parseFloat(hw);
	
	//  Potsdam Datum / Bessel Ellipsoid
	// Große Halbachse a und Abplattung f
	   a = 6377397.155;
	   f = 3.34277321e-3;
	   pi = Math.PI;
	
	// Polkrümmungshalbmesser c
	   c = a/(1-f);
	
	// Quadrat der zweiten numerischen Exzentrizität
	   ex2 = (2*f-f*f)/((1-f)*(1-f));
	   ex4 = ex2*ex2;
	   ex6 = ex4*ex2;
	   ex8 = ex4*ex4;
	
	// Koeffizienten zur Berechnung der geographischen Breite aus gegebener
	// Meridianbogenlänge
	   e0 = c*(pi/180)*(1 - 3*ex2/4 + 45*ex4/64 - 175*ex6/256 + 11025*ex8/16384);
	   f2 =   (180/pi)*(    3*ex2/8 - 3*ex4/16  + 213*ex6/2048 -  255*ex8/4096);
	   f4 =              (180/pi)*(  21*ex4/256 -  21*ex6/256  +  533*ex8/8192);
	   f6 =                           (180/pi)*(  151*ex6/6144 -  453*ex8/12288);
	
	// Geographische Breite bf zur Meridianbogenlänge gf = hw
	   sigma = hw/e0;
	   sigmr = sigma*pi/180;
	   bf = sigma + f2*Math.sin(2*sigmr) + f4*Math.sin(4*sigmr)
		  + f6*Math.sin(6*sigmr);
	
	// Breite bf in Radianten
	   br = bf * pi/180;
	   tan1 = Math.tan(br);
	   tan2 = tan1*tan1;
	   tan4 = tan2*tan2;
	
	   cos1 = Math.cos(br);
	   cos2 = cos1*cos1;
	
	   etasq = ex2*cos2;
	
	// Querkrümmungshalbmesser nd
	   nd = c/Math.sqrt(1 + etasq);
	   nd2 = nd*nd;
	   nd4 = nd2*nd2;
	   nd6 = nd4*nd2;
	   nd3 = nd2*nd;
	   nd5 = nd4*nd;
	
	//  Längendifferenz dl zum Bezugsmeridian lh
	   kz = parseInt(rw/1e6);
	   lh = kz*3
	   dy = rw-(kz*1e6+500000);
	   dy2 = dy*dy;
	   dy4 = dy2*dy2;
	   dy3 = dy2*dy;
	   dy5 = dy4*dy;
	   dy6 = dy3*dy3;
	
	   b2 = - tan1*(1+etasq)/(2*nd2);
	   b4 =   tan1*(5+3*tan2+6*etasq*(1-tan2))/(24*nd4);
	   b6 = - tan1*(61+90*tan2+45*tan4)/(720*nd6);
	
	   l1 =   1/(nd*cos1);
	   l3 = - (1+2*tan2+etasq)/(6*nd3*cos1);
	   l5 =   (5+28*tan2+24*tan4)/(120*nd5*cos1);
	
	// Geographischer Breite bp und Länge lp als Funktion von Rechts- und Hochwert
	   ll.lat = parseFloat(bf + (180/pi) * (b2*dy2 + b4*dy4 + b6*dy6));
	   ll.lng = parseFloat(lh + (180/pi) * (l1*dy  + l3*dy3 + l5*dy5));
	  
	   return pot_wgs(ll.lng, ll.lat);
	}
function pot_wgs(lp, bp){
	// Geographische Länge lp und Breite bp im Potsdam Datum
   var ll = {};
   if (lp == "" || bp == "" || isNaN(lp) || isNaN(bp)) return ll;    

   lp = parseFloat(lp);
   bp = parseFloat(bp);

	// Quellsystem Potsdam Datum
	//  Große Halbachse a und Abplattung fq
   a = 6378137.000 - 739.845;
   fq = 3.35281066e-3 - 1.003748e-05;

	// Zielsystem WGS84 Datum
	//  Abplattung f
   f = 3.35281066e-3;

	// Parameter für datum shift
   dx = 587;
   dy = 16;
   dz = 393;

// Quadrat der ersten numerischen Exzentrizität in Quell- und Zielsystem
   e2q = (2*fq-fq*fq);
   e2 = (2*f-f*f);

// Breite und Länge in Radianten
   pi = Math.PI;
   b1 = bp * (pi/180);
   l1 = lp * (pi/180);

// Querkrümmungshalbmesser nd
   nd = a/Math.sqrt(1 - e2q*Math.sin(b1)*Math.sin(b1));

// Kartesische Koordinaten des Quellsystems Potsdam
   xp = nd*Math.cos(b1)*Math.cos(l1);
   yp = nd*Math.cos(b1)*Math.sin(l1);
   zp = (1 - e2q)*nd*Math.sin(b1);

// Kartesische Koordinaten des Zielsystems (datum shift) WGS84
   x = xp + dx;
   y = yp + dy;
   z = zp + dz;

// Berechnung von Breite und Länge im Zielsystem
   rb = Math.sqrt(x*x + y*y);
   b2 = (180/pi) * Math.atan((z/rb)/(1-e2));

   if (x > 0)
	 l2 = (180/pi) * Math.atan(y/x);
   if (x < 0 && y > 0)
	 l2 = (180/pi) * Math.atan(y/x) + 180;
   if (x < 0 && y < 0)
	 l2 = (180/pi) * Math.atan(y/x) - 180;

   ll.lng = parseFloat(l2.toFixed(8));
   ll.lat = parseFloat(b2.toFixed(8));
   return ll;
}
</script>
<style type="text/css">  
body{font-family:Verdana, Geneva, sans-serif;font-size:12px}
</style>
</head>   
<body>
<p>Gauß-Krüger Koordinaten (Eingabe im Format r,h) in Dezimalgrad geocoden:</p>
<input type="text" id="txtAdresse" value="2567544.359,5645137.949" size="30" />  
<input type="button" id="btnRequestGK" onClick="GetLocationFromGK()" value="Geocode" />  
<div id="coords" style="margin:10px 0;background-color:#FFC; width:auto"></div>  
</body>
</html>

Grüße Uwe
Member: meinsm
meinsm Jan 15, 2017 at 18:13:24 (UTC)
Goto Top
Vielen Dank colinardo.
Hast mir sehr geholfen face-smile.
Member: meinsm
meinsm Jan 16, 2017 at 11:03:23 (UTC)
Goto Top
Leider ist das Ergebnis etwas verschoben. Woran kann dies liegen?
Member: colinardo
colinardo Jan 16, 2017 updated at 11:39:47 (UTC)
Goto Top
Das hängt von einigen Faktoren ab, das bleibt deine Hausaufgabe, wir wollen ja nicht das die Leute hier nur Copy n' Paste betreiben... face-wink