Ben bir meteor.js nuub'ım, ama bunu anlamaya çalışırken biraz zaman harcadım.Meteor.js reaktifi html5 konum belirleme konumu.coords
UI'mizi, getCurrentPosition uygulamasına geçirilen HTML5 coğrafi konum API geri çağrısı temelinde yeniden etkinleştirmeye çalışıyorum. Ancak, kullanıcı arabirimi geçerli kodumla güncellenmiyor.
Öneriler ve/veya bir çözüm önerebilir misiniz?
Temelleri: meteor sunucusu çalıştıran
Ben bir ana sayfaya sahip başarıyla koleksiyonları aracılığıyla Mongo'da/dan diğer verileri çekiyor (main.html):<head>
<title>Geolocation</title>
</head>
<body>
<div class="container">
<header class="navbar">
<div class="navbar-inner">
<a class="brand" href="/">Geolocation</a>
</div>
</header>
<div id="locationDemo">
{{> location}}
</div>
</div>
</body>
referanslar İşte detaylar bir şablon (location.js):
bu ilişkili yardımcısı vardır<template name="location">
<div>
Lat: {{lat}}
</div>
<div>
Lon: {{lon}}
</div>
</template>
(location.js):
_lat = {
current: 0,
dep: new Deps.Dependency,
get: function(){
this.dep.depend();
if(this.current === 0){
getLocation();
}
return this.current;
},
set: function(value){
this.current = value;
this.dep.changed();
Deps.flush();
return this.current;
}
};
_lon = {
current: 0,
dep: new Deps.Dependency,
get: function(){
this.dep.depend();
if(this.current === 0){
getLocation();
}
return this.current;
},
set: function(value){
this.current = value;
this.dep.changed();
Deps.flush();
return this.current;
}
};
function getLocation(){
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(showPosition, showError);
}
else{
console.log("Geolocation is not supported by this browser.");
}
}
function showPosition(position)
{
_lat.set(position.coords.latitude);
_lon.set(position.coords.longitude);
}
function showError(error) {
switch(error.code) {
case error.PERMISSION_DENIED:
console.log("User denied the request for Geolocation.");
break;
case error.POSITION_UNAVAILABLE:
console.log("Location information is unavailable.");
break;
case error.TIMEOUT:
console.log("The request to get user location timed out.");
break;
case error.UNKNOWN_ERROR:
console.log("An unknown error occurred.");
break;
}
}
Template.location.helpers({
lat: _lat.get(),
lon: _lon.get()
});
mevcut coğrafi konum paketi eklemek için gerekli bunu bekliyoruz navigator.geolocation.getCurrentPosition 'değiştiğinde güncellemek için? Eğer öyleyse, muhtemelen bir Deps.autorun'a ihtiyacınız olacak, ancak o zaman bile coğrafi konumun reaktif bir veri kaynağı olarak kullanılabileceğinden emin değilim. –
Hey Cristian, evet, _lat ve _lon'un reaktif vars olarak kullanılabileceğini düşündüm. Deps.autorun'u düşünüyordum ama nerede arayacağımı bilmiyorum. –