我在文檔中隨處搜索,以解釋如何只顯示融合表給定區域的標記。谷歌地圖,融合表和標記
目前所有標記出現在地圖上,像這樣:
JSFiddle (note jsfiddle wont load the uri from website so markers wont show)
如果你點擊融合表/谷歌地圖,我得到的面積區域名稱按預期彈出,但我不想在最初顯示任何標記。當點擊融合表/地圖區域時,我希望它僅顯示該給定區域的標記,而不是整個地圖。
這是我如何添加標記到地圖,從我的Web API:
var uri = 'http://mountainsandweather.azurewebsites.net/api/Mountains';
$(document).ready(function() {
//Get web api json data
$.getJSON(uri)
.done(function (data) {
// On success, 'data' contains a list of mountains.
$.each(data, function (key, item) {
// Add a list item for the mountain.
$('<li>', { text: formatItem(item) }).appendTo($('#mountains'));
//Put seperate data fields into one variable
var latLng = new google.maps.LatLng(item.Latitude, item.Longitude);
//Add info window to each marker
var infowindow = new google.maps.InfoWindow({
content: formatItemInfoWindow(item)
});
// Creating a marker and putting it on the map
var marker = new google.maps.Marker({
position: latLng,
title: formatItemInfoWindow(item.Name),
infowindow: infowindow
});
marker.setMap(map);
google.maps.event.addListener(marker, 'click', function() {
//this.infowindow.close(); //not working correctly info windows still show
this.infowindow.open(map, marker);
});
});
});
});
function formatItemInfoWindow(item) {
return item.Name + '<br />' + item.Height_ft + '<br />' + item.humidity + '<br />' + item.snowCover + '<br />' + item.temperature;
}
function formatItem(item) {
return item.Latitude +', '+ item.Longitude;
}
}
我的文檔中看到,可以加入到融合表一where
聲明。像這樣:
var layer = new google.maps.FusionTablesLayer({
query: {
select: 'geometry',
from: '11RJmSNdTr7uC867rr2zyzNQ6AiE1hcREmGFTlvH3'
where: //not sure if I could use this or what to put.
},
但是,來自Web API的數據沒有被分割到特定的區域,它只是一個長和寬的經緯度列表。像這樣:
<Mountain>
<Height_ft>2999</Height_ft>
<Height_m>914</Height_m>
<ID>c1</ID>
<Latitude>57.588007</Latitude>
<Longitude>-5.5233564</Longitude>
<Name>Beinn Dearg</Name>
<humidity>0.81</humidity>
<snowCover>4.99</snowCover>
<temperature>63</temperature>
</Mountain>
谷歌有沒有什麼在融合表幾何與座標混合的方式?顯示給定區域的所有標記的簡單方法?或者任何人都可以想到這樣做的方式?
有關的WebAPI一些額外的細節櫃面它是需要:
private MountainContext db = new MountainContext();
// GET: api/Mountains
public IQueryable<Mountain> GetMountains()
{
return db.Mountains;
}
// GET: api/Mountains/5
[ResponseType(typeof(Mountain))]
public IHttpActionResult GetMountain(string id)
{
Mountain mountain = db.Mountains.Find(id);
if (mountain == null)
{
return NotFound();
}
return Ok(mountain);
}
public IQueryable<Mountain> GetMountainByName(string name)
{
return db.Mountains.Where(n => string.Equals(n.Name, name));
}
你也必須存儲標記在FusionTable的選項? –