将侦听器附加到KML层:
var layer = new google.maps.KmlLayer('http://sites.google.com/site/kmlprototypes/kmls/temp.kml?dc_=' + Math.random(),
{suppressInfoWindows:true,preserveViewport:true});
layer.setMap(map);
google.maps.event.addListener(layer, 'click', function (obj) {
alert(obj.featureData.id);
});
Run Code Online (Sandbox Code Playgroud)
KML文件有效(通过验证api检查),您可以在此处找到它.XML中的每个地标都有id属性,如:
<Placemark id="46">
<Style>
<IconStyle>
<Icon>
<href>
<![CDATA[http://chart.apis.google.com/chart?chf=bg,s,EAF7FE02&chxt=y&chbh=a,4,4&chs=48x48&cht=bvg&chco=FF0000,0000FF&chds=20,9048.00,0,9048.00&chd=t:8149.00|9048.00]]>
</href>
</Icon>
</IconStyle>
</Style>
<Point>
<coordinates>30.49566650390625,50.721378326416016</coordinates>
</Point>
</Placemark>
Run Code Online (Sandbox Code Playgroud)
当点击谷歌地图对象中的地标时返回正确的ID,但有时大约50%的时间obj.featuredData.id是null(ZERO_RESULTS状态在status字段中).我尝试过不同的数据集(从100点到1000点),但没有用.我也尝试过lat,lng的不同精度.
尝试创建 SQS 轮询器:
作为一个例子,我正在使用这个JavaRx 实现,它很容易转换为 Project Reactor 并通过背压对其进行丰富。
private static final Long DEFAULT_BACKOFF = 500L;
private static final Long MAX_BACKOFF = 8000L;
private static final Logger LOGGER = LoggerFactory.getLogger(SqsPollerService.class);
private static volatile boolean stopRequested;
public Flux<Message> pollMessages(GetQueueUrlResult q)
{
return Flux.create(sink -> {
long backoff = DEFAULT_BACKOFF;
while (!stopRequested)
{
if (sink.isCancelled())
{
sink.error(new RuntimeException("Stop requested"));
break;
}
Future<ReceiveMessageResult> future = sink.requestedFromDownstream() > 0
? amazonSQS.receiveMessageAsync(createRequest(q))
: completedFuture(new ReceiveMessageResult());
try …Run Code Online (Sandbox Code Playgroud)