[Mapkit.js] mapkit.Search returning 500 errors

When searching via mapkit.Search, I run into a 500 Internal Server Error:


URL in network console: https://api.apple-mapkit.com/v1/search?q=restaurants&searchLocation=40.7185%2C-73.990139&lang=en

error: {message: "Error processing your request", details: []}


(All requests are authorized so that's not the issue).


Code is below.



    var listRestaurants = function(error, data) {
      console.log(data);
    }

    $(document).on('click', '.restaurants', function() {
      var coord = new mapkit.Coordinate($(this).data('lat'), $(this).data('lng'));
      var restaurantSearch = new mapkit.Search({
        coordinate: coord
      });
      restaurantSearch.search('restaurants', listRestaurants);
    });

Accepted Reply

The way I fixed this was by adding getsUserLocation:false (or true) in the SearchOptions object.


var search = new mapkit.Search({ getsUserLocation: false, region: map.region }); //search the current visible map region 
search.search("restaurant", function(error, data) { console.log(data);});


Not sure why that seems to fix it, but it did. Hopefully this gets documented or fixed in the future.

Replies

I'm not seeing 500s at the moment, tested with the example below.


var search = new mapkit.Search({ region: map.region }); //search the current visible map region
search.search("restaurants", function(error, data){console.log(data);} );

I still get an error. Console screenshot is here (token is obfuscated): https://darshanbib.s3.amazonaws.com/Screen-Shot-2019-01-12-at-11.40.38-AM.pnghttps://darshanbib.s3.amazonaws.com/Screen-Shot-2019-01-12-at-11.40.38-AM.png


The code I ran is the what you pasted above:

      var search = new mapkit.Search({ region: map.region }); //search the current visible map region  
      search.search("restaurants", function(error, data){console.log(data);} ); 


I am running this on https://localhost:8443, not sure if that matters (other requests to mapkitJS on localhost have no issues). Happens in all browsers I tested (Safari Desktop 12.0.1, Chrome Desktop v71.0.3578.9).

Does your token include an origin claim? Is the map loading but Search is not working, or is the map also not showing up?

Hi there!


I'm also seeing 500 errors on search in a project that previously worked as expected (source and app are available at https://glitch.com/~bagel-finder should you want to take a closer look).


While I wasn't originally sending an origin claim in server.js (it was causing 401 errors in Safari and Firefox), the app demo worked as expected. I'm doing now sending the origin claim, and I still get the following console errors:


GET https://api.apple-mapkit.com/v1/search?q=bagel&searchLocation=40.704617%2C-74.011233&lang=en 500 (Internal Server Error)
Error: Network error
    at Object.loaderDidFail (mapkit.js:3)
    at n.loaderDidFail (mapkit.js:3)
    at n.handleEvent (mapkit.js:3)

I'm not sure why the first line removes the GET request URL when I format it as code, but the entire line is:


GET https://api.apple-mapkit.com/v1/search?q=bagel&searchLocation=40.704617%2C-74.011233&lang=en 500 (Internal Server Error)


The map otherwise loads as expected. I do need to add some async/await in the client-side JS, but otherwise this was working fine. Originally this was written against v5.0.x and now I'm calling the latest version of MapKit from the CDN (5.13.0), but I didn't see anything in the release notes to suggest that I need to change anything in my codebase.


If you've got any thoughts on what I'm doing wrong, I'd greatly appreciate it. 🙂

The rest of the map shows and other functions work. Are there any special settings required to authenticate to make search work?


I'm linking to the following mapkitJS script: https://cdn.apple-mapkit.com/mk/5.x.x/mapkit.js

Hi Vicki, any update on this issue?

The way I fixed this was by adding getsUserLocation:false (or true) in the SearchOptions object.


var search = new mapkit.Search({ getsUserLocation: false, region: map.region }); //search the current visible map region 
search.search("restaurant", function(error, data) { console.log(data);});


Not sure why that seems to fix it, but it did. Hopefully this gets documented or fixed in the future.

Could you share the output of your search result? This doesn't return a 500 Internal Server Error for me anymore, but I also don't get any results for "restaurant":


{places: Array(0), query: "restaurant"}


My search is using the coordinate parameter centered in Manhattan's Financial District, so I definitely expect something to be returned.


What fixed the 500 error was using coordinate: map.locationCoordinate instead of coordinate: locationCoordinate — not adding the getsUserLocation argument.


Interestingly, I get a bad request if I try to use region: instead of coordinate: for some reason.