I created a PointsOfInterestSearch (https://developer.apple.com/documentation/mapkitjs/pointsofinterestsearch) on the frontend using MapKit JS:
const poiSearch = new window.mapkit.PointsOfInterestSearch({
center: new mapkit.Coordinate(userLocation.lat, userLocation.lng),
radius: 10000,
});
poiSearch.search((error, results) => {
console.log("Length of poiSearch:", results.places.length);
results.places.forEach((place) => {
console.log("Name:", place.name);
});
});
The length of results.places is 20. Trying it with a bigger radius also still results in 20.
The docs for PointsOfInterestSearchResponse shows only a places (https://developer.apple.com/documentation/mapkitjs/pointsofinterestsearchresponse) and no options for pagination.
How can I paginate the rest of the results?
Post
Replies
Boosts
Views
Activity
When using Search.autocomplete and getting the results, each search result object has coordinate which have 13 decimal places. When you use Geocoder.reverseLookup for these coordinates, it returns the wrong address and different coordinates (6 decimal places and different as well). What works is using Geocoder.lookup (with getsUserLocation as true) and putting in the Search.autocomplete displayLines (as a string) for the query. Am I doing something wrong or is this a bug?
Code:
const exampleQuery = '<example address>';
const search = new mapkit.Search({
getsUserLocation: true,
});
search.autocomplete(
exampleQuery,
(error, data) => {
if (error) {
console.error('Search error:', error);
return;
}
const { coordinate } = data.results[0];
console.log("Autocomplete coordinate", coordinate); // Lat and lng are both have 13 decimal places
const geoCoder = new mapkit.Geocoder({});
geoCoder.reverseLookup(
new mapkit.Coordinate(coordinate.latitude, coordinate.longitude),
(error, data) => {
const { formattedAddress, coordinate } = data.results[0];
console.log(formattedAddress, coordinate); // Not the same address from example query and from the search autocomplete, also the coordinate has 7 decimal places
}
);
},
{}
);