2016-04-09 6 views
1

NodeJSでMongodbのデータを使用してGoogleマップマーカーを設定するには、いくつかの助けが必要です。ノードMongodbモデルからGoogleマップマーカーを挿入する

これは私のモデルスキーマ(モデル/ listing.js)です:

var restful = require('node-restful'); 
var mongoose = restful.mongoose; 

// Schema 
var listingSchema = new mongoose.Schema({ 
    category: String, 
    title: String, 
    location: String, 
    latitude: Number, 
    longitude: Number, 
    url: String, 
    type: String, 
    type_icon: String 
}, 
    { collection: 'listing' } 
); 

// Return Model 
module.exports = restful.model('Listing', listingSchema); 

私は/ API /リストを取得するために郵便配達を使用する場合、これは私が私のインデックスに

[{ 
"_id": "57092ca64f43442f0bcd6a95", 
"category": "services", 
"title": "Musa 24 hours Printing", 
"location": "16 Bali Lane, Singapore 189852", 
"latitude": 1.3007598, 
"longitude": 103.8588499, 
"url": "http://www.musa-group.com/24hrsinternet/printing.html", 
"type": "Printing", 
"type_icon": "assets/icons/media/text.png", 
"gallery": [ 
    "http://i.imgur.com/HwiyMCK.png" 
]}, 
    { 
    "_id": "57092ca64f43442f0bcd6a96", 
    "category": "services", 
    "title": "Rocket Printers SG", 
    "location": "146 Jalan Bukit Merah, Singapore 160146", 
    "latitude": 1.2778769, 
    "longitude": 103.8308443, 
    "url": "http://www.rocketprinters-sg.com/", 
    "type": "Printing", 
    "type_icon": "assets/icons/media/text.png", 
    "gallery": [ 
     "http://i.imgur.com/XPYgZ7a.jpg" 
    ] 
    }] 

を持っているものです.ejsファイルは、マーカーは、現在、私は「items.json.txt」からソースを変更するにはどうすればよいitems.json.txtファイル

<script> 
var _latitude = 1.36080344; 
var _longitude = 103.81565094; 
var jsonPath = 'assets/json/items.json.txt'; 
    // Load JSON data and create Google Maps 
    $.getJSON(jsonPath) 
     .done(function(json) { 
      createHomepageGoogleMap(_latitude,_longitude,json); 
     }) 
     .fail(function(jqxhr, textStatus, error) { 
      console.log(error); 
     }); 
    // Set if language is RTL and load Owl Carousel 
    $(window).load(function(){ 
     var rtl = false; // Use RTL 
     initializeOwl(rtl); 
    }); 
    autoComplete(); 
</script> 

から引っ張られます私の 'リスト'データベースコレクションに?どんな助けにも大いに感謝しています!

答えて

0

あなたのJSONファイルを/ API /リストで返されるJSONと同じ構造をしていると仮定すると、あなたは、単にサーバーyourserverを想定し、yourserver.com:XX/api/listingしてJSONファイルのURLを置き換えることができます。は、ポートXXでAPIを実行しています。

jQuery.getJsonメソッドは、適切なContent-Typeヘッダーのような要求にパラメータを追加する単なるラッパーであると思われます。

+0

ありがとうございます!あなたは素晴らしいです。 –

関連する問題