Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Meteor.js中的Mapbox动态标记_Javascript_Meteor_Mapbox - Fatal编程技术网

Javascript Meteor.js中的Mapbox动态标记

Javascript Meteor.js中的Mapbox动态标记,javascript,meteor,mapbox,Javascript,Meteor,Mapbox,通过向地理编码器传递存储在我的数据库中的街道地址,可以成功地动态设置mapbox视点 但是,我想在地址的位置画一个标记,而不仅仅是将地图视图设置为地址 Template.vendorPage.rendered = function(){ //get address from database by ID address = function(){ pathname =location.pathname.split("/"); thisId = pathname[2];

通过向地理编码器传递存储在我的数据库中的街道地址,可以成功地动态设置mapbox视点

但是,我想在地址的位置画一个标记,而不仅仅是将地图视图设置为地址

Template.vendorPage.rendered = function(){


//get address from database by ID
address = function(){
    pathname =location.pathname.split("/"); 
    thisId = pathname[2]; 
    return Vendors.findOne({_id: thisId}).address
}
//set variable to the address function
thisAddress = address(); 

//draw the mapbox
L.mapbox.accessToken = '<My Token Here>';
var geocoder = L.mapbox.geocoder('mapbox.places-v1'),
    map = L.mapbox.map('map', 'alexnetsch.j786e624');

geocoder.query(thisAddress, showMap);

function showMap(err, data) {
    // The geocoder can return an area, like a city, or a
    // point, like an address. Here we handle both cases,
    // by fitting the map bounds to an area or zooming to a point.
    if (data.lbounds) {
        map.fitBounds(data.lbounds);
    } else if (data.latlng) {
        map.setView([data.latlng[0], data.latlng[1]], 16);
    }
}


}

我终于明白了

Template.vendorPage.rendered = function(){
    address = function(){
        pathname =location.pathname.split("/"); 
        thisId = pathname[2]; 
        return Vendors.findOne({_id: thisId}).address
    }

    thisAddress = address(); 

    //draw the mapbox
    L.mapbox.accessToken = 'pk.eyJ1IjoiYWxleG5ldHNjaCIsImEiOiJsX0V6Wl9NIn0.i14NX5hv3bkVIi075nOM2g';
    var geocoder = L.mapbox.geocoder('mapbox.places-v1'),
        map = L.mapbox.map('map', 'alexnetsch.j786e624');

    geocoder.query(thisAddress, showMap);

    function showMap(err, data) {
        // The geocoder can return an area, like a city, or a
        // point, like an address. Here we handle both cases,
        // by fitting the map bounds to an area or zooming to a point.
        if (data.lbounds) {
            map.fitBounds(data.lbounds);
        } else if (data.latlng) {
            map.setView([data.latlng[0], data.latlng[1]], 16);
        }
    }

    var addMarker;
    addMarker = function(geocoder, map, placeName) {
      return geocoder.query(placeName, function(error, result) {
        var marker;
        marker = L.marker(result.latlng);
        return marker.addTo(map);
      });
    };

    addMarker(geocoder, map, thisAddress);
Template.vendorPage.rendered = function(){
    address = function(){
        pathname =location.pathname.split("/"); 
        thisId = pathname[2]; 
        return Vendors.findOne({_id: thisId}).address
    }

    thisAddress = address(); 

    //draw the mapbox
    L.mapbox.accessToken = 'pk.eyJ1IjoiYWxleG5ldHNjaCIsImEiOiJsX0V6Wl9NIn0.i14NX5hv3bkVIi075nOM2g';
    var geocoder = L.mapbox.geocoder('mapbox.places-v1'),
        map = L.mapbox.map('map', 'alexnetsch.j786e624');

    geocoder.query(thisAddress, showMap);

    function showMap(err, data) {
        // The geocoder can return an area, like a city, or a
        // point, like an address. Here we handle both cases,
        // by fitting the map bounds to an area or zooming to a point.
        if (data.lbounds) {
            map.fitBounds(data.lbounds);
        } else if (data.latlng) {
            map.setView([data.latlng[0], data.latlng[1]], 16);
        }
    }

    var addMarker;
    addMarker = function(geocoder, map, placeName) {
      return geocoder.query(placeName, function(error, result) {
        var marker;
        marker = L.marker(result.latlng);
        return marker.addTo(map);
      });
    };

    addMarker(geocoder, map, thisAddress);