Google Maps

Es gibt 2 Antworten in diesem Thema. Der letzte Beitrag () ist von mikeb69.

    Hallo,

    ich binde auf dieser Seite Google-Maps ein, um den Spielort anzeigen zu können.

    Quellcode

    1. <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
    2. <script type="text/javascript">
    3. var geocoderStart;
    4. var map;
    5. function initialize() {
    6. geocoderStart = new google.maps.Geocoder();
    7. var latlng = new google.maps.LatLng(48.393, 10.817);
    8. var myOptions = {
    9. //zoom: 17 bei Standort
    10. zoom: 17,
    11. center: latlng,
    12. mapTypeId: google.maps.MapTypeId.HYBRID
    13. }
    14. map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    15. codeStartAddress();
    16. }
    17. function codeStartAddress() {
    18. var address = document.getElementById("HiddenFieldDest").value;
    19. if (geocoderStart) {
    20. geocoderStart.geocode({ 'address': address }, function (results, status) {
    21. if (status == google.maps.GeocoderStatus.OK) {
    22. map.setCenter(results[0].geometry.location);
    23. var marker = new google.maps.Marker({
    24. map: map,
    25. position: results[0].geometry.location
    26. });
    27. } else {
    28. alert("Geocode was not successful for the following reason: " + status);
    29. }
    30. });
    31. }
    32. }
    33. </script>


    Das Problem ist, dass Google-Maps zweimal angefragt wird.
    Dies ist deutlich zu sehen.

    Wie kann ich den Code vereinfachen, sodass Google-Maps nur einmal angefragt wird ?

    Gruss

    mikeb69
    Die Frage ist, wieso die zweite Funktion?? Um die Adresse anstatt der Geocoords zu Centern?? Also ich nutze GoogleMaps API folgendermaßen

    Quellcode

    1. function initialize() {
    2. var geocoder = new google.maps.Geocoder();
    3. geocoder.geocode( { 'address': 'strasse 13, 123456 ort'}, function(results, status) {
    4. if(status == google.maps.GeocoderStatus.OK) {
    5. var myOptions = {
    6. zoom: 14,
    7. center: results[0].geometry.location,
    8. mapTypeId: google.maps.MapTypeId.ROADMAP,
    9. mapTypeControl: false,
    10. navigationControl: true,
    11. navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL}
    12. };
    13. var map = new google.maps.Map(document.getElementById("googlemap"), myOptions);
    14. var marker = new google.maps.Marker({
    15. position: results[0].geometry.location,
    16. map: map,
    17. icon: 'images/gmap_marker.png'
    18. });
    19. } else {
    20. alert("Geocode was not successful for the following reason: " + status);
    21. }
    22. });
    23. }
    24. initialize();