Nasıl (çabuk - 15-20ms) bulurum LatLong Javascript kullanarak bir Adres?

oy
2

Yeni Adresini her 15-20ms pingleyen bir socket.io var. Bu Adres için, ben Lat-Long olsun ve Google Maps işaret yerleştirmek gerekir. Yani bu 15-20ms içinde ben Coğrafi Konum almak zorunda (değilse, 50-60ms içinde olabilir). Şu anda kullanıyorum geocoder = new google.maps.Geocoder();o zaman vegeocoder.geocode({address: data}, myFunction(){});

Ama Haritalar için bu API çok yavaş. Benim ara Adres boş istekleri vermektedir 400-500ms coğrafi konumu döndürür. Ben çok hızlı bir API gerekir.

Referans olarak, aşağıdaki socket.io için kod parçası olduğu:

geocoder = new google.maps.Geocoder();
    var socket = io.connect('http://localhost');
    socket.on('new_address', function (data) {
        //Gets called everytime a new request for GeoLocation comes
        geocoder.geocode({address: data}, placeMarker);
    });

var placeMarker = function(){
    //Add Marker to GoogleMaps
};
Oluştur 25/02/2013 saat 13:29
kaynak kullanıcı
Diğer dillerde...                            


1 cevaplar

oy
0

yorumlarda belirtildiği gibi aslında internet üzerinde 20ms içinde bir yanıt, sadece o şekilde çalışmıyor bekleyemezsiniz. Ne ancak yapabileceğiniz adresleri ile havuzun bir tür hale getiriyor ve kendi hızına üzerinde çalışmak geocoder (veya 4 belki 3) izin verin.

Bu muhtemelen (, sadece burada bir yön veren o hemen çalışmaya sanmıyoruz) biraz şuna benzer:

var addresses = [];
var socket = io.connect('http://localhost');
socket.on('new_address', function (data) {
    //Gets called everytime a new request for GeoLocation comes
    //Adds an address to the list when it comes in from the backend
    adresses.push(data);
});

var geocoder = new google.maps.Geocoder();
//This function is called in a loop.
var addressCheck = function() {
    //When the list of addresses is empty, because we haven't received anything from the backend, just wait for a bit and call this function again.
    if(addresses.length == 0) {
        setTimeout(addressCheck, 400);
        return;
    }
    //Get the first one on the list.
    var data = addresses[0];
    //Process it.
    geocoder.geocode({address: data}, function() {
        placeMarker();
            //remove the first element from the adresses list.
        addresses.shift();
            //Call the entire function again, so it starts with a new address.
        addressCheck();
    });
}
var placeMarker = function(){
    //Add Marker to GoogleMaps
};

addressCheck();
Cevap 25/02/2013 saat 22:44
kaynak kullanıcı

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