Google지도 API를 사용하여이 라이브러리를 사용하여 특정 위치의 병원을 찾으려고합니다 : https://developers.google.com/maps/documentation/javascript/places.각도 2의 google map api 통합
요청을 콘솔에 표시하고 결과를 표시하려고했지만 결과를 변수에 넣어 html 페이지의 ngFor를 사용하여 표시하고 싶습니다.이 위치에서이 문제를 발견했습니다.
hospSearch_res:any[] = [];
searchHospitals(){
console.log('Search works');
console.log(this.hosp_lat);
console.log(this.hosp_lng);
console.log(this.hosp_rad);
var search_loc = new google.maps.LatLng(this.lat,this.lng);
var request = {
location: search_loc,
radius: '1000',
types: ['hospital']
};
var service = new google.maps.places.PlacesService(document.getElementById('test'));
service.nearbySearch(request, this.callback);
}
callback(results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
// this.hospSearch_res = results;
//let res = JSON.stringify(results);
console.log(results);
this.hospSearch_res = results;
for (var i = 0; i < results.length; i++) {
var place = results[i];
//this.hospSearch_res.push(place);
/*console.log(results[i]);
console.log(results[i].name);*/
}
}
}
이 각 2 내 첫 번째 프로젝트이며, 나는이 문제에 대한 stcuk있어, 어떤 도움이 많이 주시면 감사하겠습니다 : enter image description here
여기 내 코드입니다. 당신이
그것은이 정의되지 않은 말한다 .. – Robert
예 그 오류가 있었다. Karbos 응답 문제가 해결되었습니다. 어쨌든 고맙습니다. – Riadh
안녕하세요, 각도가 2입니다. Google지도 API에 대한 angular2에서 서비스를 만드는 방법을 알려주세요. –