Template.home.onCreated(function() {
// We can use the `ready` callback to interact with the map API once the map is ready.
GoogleMaps.ready('Map', function(map) {
// Add a marker to the map once it's ready
var marker = new google.maps.Marker({
position: map.options.center,
map: map.instance
});
var request = {
location: map.options.center,
radius:10000,
types:['restaurant']
}
console.log(request)
var service = new google.maps.places.PlacesService(map);
service.nearbySearch(request,callback);
console.log("Calling Service")
function callback(results,status)
{
console.log("Service Called")
if(status === google.maps.places.PlacesServiceStatus.OK)
{
console.log("Status OK")
for(var i = 0;i < results.length;i++)
{
console.log(results[i])
createMarker(results[i]);
}
}
}//end of callback
function createMarker(place)
{
var placeLoc = place.geometry.location;
var marker = new google.maps.Marker({
map:map,
position:place.geometry.location
});
}//end of create marker
})//end of google maps.ready function
});
У меня есть простое приложение, предназначенное для поиска мест и размещения маркеров по результатам на карте. Карта отображается правильно, и я пробовал такую же настройку в обычном приложении html и js. У меня возникли проблемы с его внедрением в моем приложении метеорита. Приложение останавливается, когда оно достигает вызова var service = new google.maps.places.PlacesService(map);
, и я получаю эту ошибку на своей консоли Uncaught TypeError: this.j.getElementsByTagName is not a function
. Я использую пакет dburles:google-maps
.google places api не работает для метеора
Можете ли вы попробовать поместить свой код в 'Template.home.onRendered' вместо' Template.home.onCreated'. 'onRendered' будет вызываться, как только ваш пользовательский интерфейс будет готов, где вызывается' onCreated', прежде чем пользовательский интерфейс загрузится полностью. Это предположение, поскольку я мало знаю о сайтах google api. – Kishor
'var service = new google.maps.places.PlacesService (map.instance);' –
Я сделал это, и это сработало, но теперь появился мой маркер arent. Я знаю, что получаю адреса, потому что я записываю их на консоль, но маркер arent создается на карте – lagfvu