[英]How to add pins to the google maps geocode api
I am trying to combine these three things into one.我试图将这三件事合二为一。
I want to add pins like I did in fiddle 1 two the code I have in fiddle 2. However I need to use the data different data source.我想像我在小提琴 1 中所做的那样添加引脚 2 我在小提琴 2 中的代码。但是我需要使用不同的数据源。 The way I made it work in fiddle 1 was with the latitude and longitude.
我让它在小提琴 1 中工作的方式是使用纬度和经度。 But because I can not do that with the new data source I need to find a new way.
但是因为我不能用新的数据源做到这一点,所以我需要找到一种新的方法。 That is why I am trying to add it to fiddle one.
这就是为什么我试图将它添加到小提琴中。 Will that work?
那行得通吗? If so how can I do it?
如果是这样,我该怎么做? If it wont work what would you suggest using the google maps api?
如果它不起作用,您会建议使用谷歌地图 api 吗?
$.getJSON(URL, function(data, textstatus) {
$.each(data, function(i, entry) {
var contentString = '<div id="content">'+
'<div id="siteNotice">'+
'</div>'+
'<h1 id="firstHeading" class="firstHeading">' + entry.name_ + " Library" + '</h1>'+ '<hr>' +
'<div id="bodyContent">'+
'<p>' + entry.address + " " + entry.zip + '.<br>' +
'<p>' + '<a href="'+entry.website.url+'">' + entry.website.url + '</a>' + '</p>'+
'<p>' + entry.hours_of_operation + '</p>'+
'</div>'+
'</div>';
var infowindow = new google.maps.InfoWindow({
content: contentString
});
var marker = new google.maps.Marker({
position: new google.maps.LatLng(entry.location.latitude,
entry.location.longitude),
map: map,
title: entry["dba_name"] + "\n" + entry["address"]
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
});
});
Since you have 2 callback functions, the correct way to do this is to first finish work for first callback, in this case, downloading the JSON and parse them, also I would store all the entry
into entries
just so that we can use the data when we add the markers, which is called at the end of the first callback.由于您有 2 个回调函数,因此正确的方法是先完成第一个回调的工作,在这种情况下,下载 JSON 并解析它们,我还将所有
entry
存储到entries
,以便我们可以使用数据当我们添加标记时,它会在第一个回调结束时调用。
about the API access limit, sadly I think you have to use the paid google maps geocoding API, or other services like openStreetmaps.关于 API 访问限制,遗憾的是我认为您必须使用付费的谷歌地图地理编码 API,或其他服务,如 openStreetmaps。
I also have a jsfiddle setup, hope this help.我也有一个jsfiddle设置,希望这有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.