google.maps.Geocoder के साथ कार्य करना ()। अतुल्यकालिक कॉलबैक

वोट
0

मैं LatLng निर्देशांक में एक पते को जियोकोड करने की कोशिश कर रहा है, लेकिन मैं ऐसा करने में कठिनाई का एक बहुत हो रही है। मैं जानता हूँ कि geocode()एक अतुल्यकालिक समारोह है, और मैं कोई लाभ नहीं हुआ साथ कॉलबैक साथ कर रहा है। मैं इस तरह अन्य पदों को देखकर किया गया है ( कैसे एक अतुल्यकालिक कॉलबैक फ़ंक्शन से मान देने के लिए? ), लेकिन मुझे कठिनाई अवधारणा को समझने आ रही है। किसी को भी मुझे दिखाओ कैसे ठीक है कि कॉलबैक फ़ंक्शन करने के लिए कर सकते हैं, बहुत सराहना की जाएगी। यह एक से अधिक सिर दर्द के बहुत सारे। कॉलबैक एक ऐसा करने के लिए प्राप्त करने में सक्षम था alert()कि सही LatLng देता है, लेकिन स्थिति पैरामीटर सेट नहीं। क्षमा करें उदाहरण पहले उद्धृत से यह पता लगा नहीं कर सका। सुंदर भाषा के लिए नया। तुम मुझे इंगित कर सकते हैं अवधारणा को समझने के लिए किसी भी संदर्भ में भी काफी सराहना कर रहे हैं। धन्यवाद!

  var location;
  var image;
  var map;
  var geocoder;
  var address;

  function initialize() {
    var mapOptions = {
      center: new google.maps.LatLng(42.763146, -73.3776),
      zoom: 6,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById(map_canvas),
        mapOptions);
    var cloudLayer = new google.maps.weather.CloudLayer();
    cloudLayer.setMap(map);

    addressSet(function(address) {
        console.log(address);
        // tried to set location = address;, location = new google.maps.LatLng(address);
        // neither works
    });

    addMtsToMap(location,
                map,
                new google.maps.MarkerImage(img/mts/skier.png, null, null, null, new google.maps.Size(50,50)));

  }

  function addMtsToMap(location, map, image) {

    var marker = new google.maps.Marker({
        position: location,
        map: map,
        icon: image
    });

    var infoWindow = new google.maps.InfoWindow({content: <h1>Powder!!!</h1>});

    google.maps.event.addListener(marker, click, function() {
        infoWindow.open(map, marker);
    });
  }

  function addressSet(callback) {

    geocoder = new google.maps.Geocoder();

    geocoder.geocode({address: Killington+VT}, function(results, status) {

        if (status == google.maps.GeocoderStatus.OK) {

            address = results[0].geometry.location;
            callback(address);
        }
    });
  }
13/02/2013 को 01:41
का स्रोत उपयोगकर्ता
अन्य भाषाओं में...                            


1 जवाब

वोट
0

क्षमा करें सब। विश्वास नहीं कर सकता मैं इतने लंबे समय के लिए इस के साथ खिलवाड़ के बाद क्या मिला। मैं घोषित var mapइनिशियलाइज़, जो मेरी बनाया में फिर से addressSet()समारोह खींच गलत वैश्विक मानचित्र चर। हटाया जा रहा है वर यह काम कर दिया।

13/02/2013 को 19:48
का स्रोत उपयोगकर्ता

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more