Witam, zaimplementowałem na stronie mapę Google korzystając z API Googli. Kod wygląda mniej więcej tak:
  1. <script type="text/javascript">
  2.  
  3.    var gMap2;
  4.    var gDirections;
  5.    var geocoder = null;
  6.    var addressMarker;
  7.  
  8.    function initialize()
  9.    {
  10.        if (GBrowserIsCompatible()) {
  11.            gMap2 = new GMap2( $('map') );
  12.            //gMap2.disableGoogleBar();
  13.            
  14.            gDirections = new GDirections(gMap2/*, $('directions')*/);
  15.            GEvent.addListener(gDirections, "load", onGDirectionsLoad);
  16.            GEvent.addListener(gDirections, "error", handleErrors);
  17.  
  18.            <? if( $this->directions ): ?>
  19.            setDirections("<? echo $this->startCity ?>", "<? echo $this->finishCity ?>", "pl");
  20.            <? else: ?>
  21.            gMap2.setCenter( new GLatLng( 55, 25 ), 3 );
  22.            <? endif; ?>
  23.            
  24.            //alert( 'Podaj obie lokalizacje' );
  25.            
  26.        }
  27.    }
  28.  
  29.    function setDirections(fromAddress, toAddress, locale)
  30.    {
  31.        gDirections.load("from: " + fromAddress + " to: " + toAddress, { "locale": locale });
  32.    }
  33.  
  34.    function handleErrors()
  35.    {
  36.        if (gDirections.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
  37.        alert('Podana lokalizacja nie została odnaleziona');
  38.        else if (gDirections.getStatus().code == G_GEO_SERVER_ERROR)
  39.        alert('Błąd serwera');
  40.  
  41.        else if (gDirections.getStatus().code == G_GEO_MISSING_QUERY)
  42.        alert('Błąd podczas komunikacji z serwerem');
  43.  
  44.        else if (gDirections.getStatus().code == G_GEO_BAD_KEY)
  45.        alert('Nieprawidłowy klucz');
  46.  
  47.        else if (gDirections.getStatus().code == G_GEO_BAD_REQUEST)
  48.        alert('Błąd podczas przetwarzania danych');
  49.  
  50.        else alert('Wystąpił nieznany błąd');
  51.  
  52.    }
  53.  
  54.    function onGDirectionsLoad()
  55.    {
  56.        
  57.    }
  58. </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:

  1. <script type="text/javascript">
  2.  
  3.    var gMap;
  4.    var gDirections;
  5.    var geocoder = null;
  6.    var addressMarker;
  7.  
  8.    function initialize()
  9.    {
  10.        if (GBrowserIsCompatible()) {
  11.            gMap = new GMap2( $('map') );
  12.            gMap.addControl( new GLargeMapControl() );
  13.             var mapTypes = gMap.getMapTypes();
  14.            mapTypes[0].getName= function() { return "Mapa";}
  15.            mapTypes[1].getName = function() { return "Satelitarna";}
  16.            mapTypes[2].getName = function() { return "Hybrydowa";}
  17.            gMap.addControl(new GMapTypeControl());
  18.            gMap.enableContinuousZoom();
  19.            gMap.enableDoubleClickZoom();
  20.            //gMap.disableGoogleBar();
  21.            
  22.            geocoder = new GClientGeocoder();
  23.            
  24.            gDirections = new GDirections(gMap/*, $('directions')*/);
  25.            GEvent.addListener(gDirections, "load", onGDirectionsLoad);
  26.            GEvent.addListener(gDirections, "error", handleErrors);
  27.  
  28.            <? if( $this->directions ): ?>
  29.            setDirections("<? echo $this->startCity ?>", "<? echo $this->finishCity ?>");
  30.            <? else: ?>
  31.            gMap.setCenter( new GLatLng( 55, 25 ), 3 );
  32.            <? endif; ?>
  33.            
  34.            //alert( 'Podaj obie lokalizacje' );
  35.            
  36.        }
  37.    }
  38.    
  39.    function setDirections(fromAddress, toAddress)
  40.    {
  41.        var startPoint;
  42.        var startPointFound = false;
  43.        var finishPoint;
  44.        var finishPointFound = false;
  45.      
  46.        geocoder.getLatLng(
  47.            fromAddress,
  48.            function( point ) {
  49.                //alert(point.toUrlValue());
  50.                if( ! point ) alert( "Nie znaleziono lokalizacji 1 " + fromAddress );
  51.                else
  52.                {
  53.                    if( finishPointFound ) gDirections.load( "from: " + point.toUrlValue() + " to: " + finishPoint.toUrlValue() );
  54.                    else
  55.                    {
  56.                        startPointFound = true;
  57.                        startPoint = point;
  58.                    }
  59.                }
  60.                    
  61.            }
  62.        );
  63.        
  64.        geocoder.getLatLng(
  65.            toAddress,
  66.            function( point ) {
  67.                //alert(point);
  68.                if( ! point ) alert( "Nie znaleziono lokalizacji 2 " + toAddress );
  69.                else
  70.                {
  71.                    if( startPointFound ) gDirections.load( "from: " + startPoint.toUrlValue() + " to: " + point.toUrlValue() );
  72.                    else
  73.                    {
  74.                        finishPointFound = true;
  75.                        finishPoint = point;
  76.                    }
  77.                }
  78.                    
  79.            }
  80.        );
  81.    }
  82.  
  83.    function handleErrors()
  84.    {
  85.        if (gDirections.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
  86.        alert('Podana lokalizacja nie została odnaleziona');
  87.        else if (gDirections.getStatus().code == G_GEO_SERVER_ERROR)
  88.        alert('Błąd serwera');
  89.  
  90.        else if (gDirections.getStatus().code == G_GEO_MISSING_QUERY)
  91.        alert('Błąd podczas komunikacji z serwerem');
  92.  
  93.        else if (gDirections.getStatus().code == G_GEO_BAD_KEY)
  94.        alert('Nieprawidłowy klucz');
  95.  
  96.        else if (gDirections.getStatus().code == G_GEO_BAD_REQUEST)
  97.        alert('Błąd podczas przetwarzania danych');
  98.  
  99.        else alert('Wystąpił nieznany błąd');
  100.  
  101.    }
  102.  
  103.    function onGDirectionsLoad()
  104.    {
  105.        
  106.    }
  107. </script>