Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

result event not emitted for a two different results which share the same id #293

Closed
dhermyt opened this issue Sep 16, 2019 · 5 comments
Closed
Labels

Comments

@dhermyt
Copy link

dhermyt commented Sep 16, 2019

Hi,

The steps to reproduce:

  1. Search for an address, like Bay Avenue 1. The map zooms in and Result event is called.
  2. Search for a nearby address, like Bay Avenue 2. The map recenters on the new location, but the Result is not called.

Why Result is not called in the second step? How to make the event raise on every search?

@andrewharvey
Copy link
Collaborator

andrewharvey commented Sep 16, 2019

There was a bug in mapbox-gl-geocoder where the result event was fired twice for a single result, #99 and tristen/suggestions#13. We could never work out how to properly fix that while still supporting IE11 and for all ways you can select a result.

So instead a fix was implemented that simply does a precheck to see if the result event being fired is for the same result, and if it is ignore it, a workaround for the underlying issue, but mostly works fine.

In this scenario those two addresses are returning the same id, because the id is the same mapbox-gl-geocoder things the second result event is just a duplicate of the first and hence does not fire.

The Geocoding API documentation at https://docs.mapbox.com/api/search/#geocoding-response-object is not entirely clear if this id in the response is absolutely unique or under which circumstances the same id is returned.

If this is simply an error in the upstream Mapbox Geocoding API, then we'll need to wait for a fix there.

If not and some results may have the same id we'll need to rethink how to address #99.

1 Bay Avenue

{
  "id": "address.3291212928152738",
  "type": "Feature",
  "place_type": [
    "address"
  ],
  "relevance": 1,
  "properties": {
    "accuracy": "interpolated"
  },
  "text_en-US": "Bay Avenue",
  "place_name_en-US": "1 Bay Avenue, Welland, Ontario L3B 3G3, Canada",
  "text": "Bay Avenue",
  "place_name": "1 Bay Avenue, Welland, Ontario L3B 3G3, Canada",
  "center": [
    -79.246267,
    42.949539
  ],
  "geometry": {
    "type": "Point",
    "coordinates": [
      -79.246267,
      42.949539
    ],
    "interpolated": true
  },
  "address": "1",
  "context": [
    {
      "id": "postcode.4926389830389270",
      "text_en-US": "L3B 3G3",
      "text": "L3B 3G3"
    },
    {
      "id": "place.3630735081406220",
      "wikidata": "Q424773",
      "text_en-US": "Welland",
      "language_en-US": "en",
      "text": "Welland",
      "language": "en"
    },
    {
      "id": "region.7377835739263190",
      "short_code": "CA-ON",
      "wikidata": "Q1904",
      "text_en-US": "Ontario",
      "language_en-US": "en",
      "text": "Ontario",
      "language": "en"
    },
    {
      "id": "country.4282270149587150",
      "short_code": "ca",
      "wikidata": "Q16",
      "text_en-US": "Canada",
      "language_en-US": "en",
      "text": "Canada",
      "language": "en"
    }
  ]
}

2 Bay Avenue
{
  "id": "address.3291212928152738",
  "type": "Feature",
  "place_type": [
    "address"
  ],
  "relevance": 1,
  "properties": {
    "accuracy": "interpolated"
  },
  "text_en-US": "Bay Avenue",
  "place_name_en-US": "2 Bay Avenue, Welland, Ontario L3B 3G3, Canada",
  "text": "Bay Avenue",
  "place_name": "2 Bay Avenue, Welland, Ontario L3B 3G3, Canada",
  "center": [
    -79.246271,
    42.949492
  ],
  "geometry": {
    "type": "Point",
    "coordinates": [
      -79.246271,
      42.949492
    ],
    "interpolated": true
  },
  "address": "2",
  "context": [
    {
      "id": "postcode.4926389830389270",
      "text_en-US": "L3B 3G3",
      "text": "L3B 3G3"
    },
    {
      "id": "place.3630735081406220",
      "wikidata": "Q424773",
      "text_en-US": "Welland",
      "language_en-US": "en",
      "text": "Welland",
      "language": "en"
    },
    {
      "id": "region.7377835739263190",
      "short_code": "CA-ON",
      "wikidata": "Q1904",
      "text_en-US": "Ontario",
      "language_en-US": "en",
      "text": "Ontario",
      "language": "en"
    },
    {
      "id": "country.4282270149587150",
      "short_code": "ca",
      "wikidata": "Q16",
      "text_en-US": "Canada",
      "language_en-US": "en",
      "text": "Canada",
      "language": "en"
    }
  ]
}

@andrewharvey andrewharvey changed the title Why geocoder is not returning result for nearby addresses? result event not emitted for a two different results which share the same id Sep 16, 2019
@scottsfarley93
Copy link

Going to check in on this one and see if I can find anything on the ID side.

@scottsfarley93
Copy link

After some digging, it seems that we shouldn't rely on deduplicating features by ID, particularly for features that are geographically very close to one another. As this is not a data issue, we should find a way to fix this client-side.

@andrewharvey
Copy link
Collaborator

In that case, having some duplicate result events due to tristen/suggestions#13 is probably better than the alternative of some searches not working when the id matches. The alternative could be to store the whole result (ie. the whole carmen geojson feature) and compare that.

@scottsfarley93
Copy link

This was fixed in #298 and will be included in the upcoming v4.5.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants