<script type="text/javascript"> var gMap2; var gDirections; var geocoder = null; var addressMarker; function initialize() { if (GBrowserIsCompatible()) { gMap2 = new GMap2( $('map') ); //gMap2.disableGoogleBar(); gDirections = new GDirections(gMap2/*, $('directions')*/); GEvent.addListener(gDirections, "load", onGDirectionsLoad); GEvent.addListener(gDirections, "error", handleErrors); <? if( $this->directions ): ?> <? else: ?> gMap2.setCenter( new GLatLng( 55, 25 ), 3 ); <? endif; ?> //alert( 'Podaj obie lokalizacje' ); } } function setDirections(fromAddress, toAddress, locale) { gDirections.load("from: " + fromAddress + " to: " + toAddress, { "locale": locale }); } function handleErrors() { if (gDirections.getStatus().code == G_GEO_UNKNOWN_ADDRESS) alert('Podana lokalizacja nie została odnaleziona'); else if (gDirections.getStatus().code == G_GEO_SERVER_ERROR) alert('Błąd serwera'); else if (gDirections.getStatus().code == G_GEO_MISSING_QUERY) alert('Błąd podczas komunikacji z serwerem'); else if (gDirections.getStatus().code == G_GEO_BAD_KEY) alert('Nieprawidłowy klucz'); else if (gDirections.getStatus().code == G_GEO_BAD_REQUEST) alert('Błąd podczas przetwarzania danych'); else alert('Wystąpił nieznany błąd'); } function onGDirectionsLoad() { } </script>
Problem w tym, że Google nie widzi niektórych dużych polskich miast z polskimi znakami, np. nie istnieje "Toruń" tylko trzeba wpisać "Torun, Kujawsko-Pomorskie, Poland". Dla odmiany "Gdańsk" widzi normalnie. Macie jakiś pomysł jak to poprawić?
NOWY POST:
W zasadzie to jest błąd w API Google albo w nazewnictwie miejscowości w bazie danych Google. Rozwiązałem to nieco inną metodą, może się komuś przyda:
<script type="text/javascript"> var gMap; var gDirections; var geocoder = null; var addressMarker; function initialize() { if (GBrowserIsCompatible()) { gMap = new GMap2( $('map') ); gMap.addControl( new GLargeMapControl() ); var mapTypes = gMap.getMapTypes(); mapTypes[0].getName= function() { return "Mapa";} mapTypes[1].getName = function() { return "Satelitarna";} mapTypes[2].getName = function() { return "Hybrydowa";} gMap.addControl(new GMapTypeControl()); gMap.enableContinuousZoom(); gMap.enableDoubleClickZoom(); //gMap.disableGoogleBar(); geocoder = new GClientGeocoder(); gDirections = new GDirections(gMap/*, $('directions')*/); GEvent.addListener(gDirections, "load", onGDirectionsLoad); GEvent.addListener(gDirections, "error", handleErrors); <? if( $this->directions ): ?> <? else: ?> gMap.setCenter( new GLatLng( 55, 25 ), 3 ); <? endif; ?> //alert( 'Podaj obie lokalizacje' ); } } function setDirections(fromAddress, toAddress) { var startPoint; var startPointFound = false; var finishPoint; var finishPointFound = false; geocoder.getLatLng( fromAddress, function( point ) { //alert(point.toUrlValue()); if( ! point ) alert( "Nie znaleziono lokalizacji 1 " + fromAddress ); else { if( finishPointFound ) gDirections.load( "from: " + point.toUrlValue() + " to: " + finishPoint.toUrlValue() ); else { startPointFound = true; startPoint = point; } } } ); geocoder.getLatLng( toAddress, function( point ) { //alert(point); if( ! point ) alert( "Nie znaleziono lokalizacji 2 " + toAddress ); else { if( startPointFound ) gDirections.load( "from: " + startPoint.toUrlValue() + " to: " + point.toUrlValue() ); else { finishPointFound = true; finishPoint = point; } } } ); } function handleErrors() { if (gDirections.getStatus().code == G_GEO_UNKNOWN_ADDRESS) alert('Podana lokalizacja nie została odnaleziona'); else if (gDirections.getStatus().code == G_GEO_SERVER_ERROR) alert('Błąd serwera'); else if (gDirections.getStatus().code == G_GEO_MISSING_QUERY) alert('Błąd podczas komunikacji z serwerem'); else if (gDirections.getStatus().code == G_GEO_BAD_KEY) alert('Nieprawidłowy klucz'); else if (gDirections.getStatus().code == G_GEO_BAD_REQUEST) alert('Błąd podczas przetwarzania danych'); else alert('Wystąpił nieznany błąd'); } function onGDirectionsLoad() { } </script>