my problem is im trying to make Searching service.
so, im trying to find some market like “공주 행복자전거” but, i can’t find by places api.
and i try google map service. (not api) and i find it.
i dont know why my script cant found. and why google map can found.
<style>
#map {height: 400px; width: 100%; }
</style>
<script src="https://maps.googleapis.com/maps/api/js?key=<?=$apiKey?>&libraries=places"></script>
<body>
<h1>장소 검색</h1>
<input id="location" type="text" placeholder="검색할 장소 입력" />
<button id="search">검색</button>
<div id="map"></div>
<script src="script.js"></script>
</body>
<script>
let map;
let service;
function initMap() {
const location = new google.maps.LatLng(-33.867, 151.195); // 초기 위치 설정
map = new google.maps.Map(document.getElementById("map"), {
center: location,
zoom: 15,
});
service = new google.maps.places.PlacesService(map);
document.getElementById("search").addEventListener("click", searchPlaces);
}
function searchPlaces() {
const locationInput = document.getElementById("location").value;
const request = {
query: locationInput,
fields: ["name", "geometry"],
};
service.findPlaceFromQuery(request, (results, status) => {
if (status === google.maps.places.PlacesServiceStatus.OK) {
for (let i = 0; i < results.length; i++) {
createMarker(results[i]);
}
map.setCenter(results[0].geometry.location);
} else {
alert("장소를 찾을 수 없습니다: " + status);
}
});
}
function createMarker(place) {
const marker = new google.maps.Marker({
map: map,
position: place.geometry.location,
title: place.name,
});
const infowindow = new google.maps.InfoWindow({
content: place.name,
});
marker.addListener("click", () => {
infowindow.open(map, marker);
});
}
google.maps.event.addDomListener(window, "load", initMap);
</script>
im trying to many type of search on places api.
findPlaceFromQuery, nearbySearch, textSearch..
but i cant find..