OpenStreetMaps auto fill selects county field for the city and saves it as city

This topic contains 12 replies, has 4 voices, and was last updated by  directoryfan 4 years, 2 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #527515

    directoryfan
    Expired Member
    Post count: 157

    Hello Support Team,

    the auto fill for the address and city does not work properly after update to v2. It chooses address.county instead address.city or address.village from the OSM-API response.

    In my opinion it should fill the listing form fields just with values like:
    Listing Address Field: address.road address.house_number, address.village (if there is an address.city or address.town, otherwise no village)
    Listing City/Location Field: address.city|town|village

    For Example:

    searching for: ‘Messingstraße 10, Legelshurst′
    OSM will suggest the address: ’10, Messingstraße, Willstätt, Ortenaukreis,…’
    and the autofill for address: ’10, Messingstraße’
    it should be:’Messingstraße 10’
    can be: ‘Messingstraße 10, Willstätt’
    and the autofill value for the City field: ‘Ortenaukreis′
    it should be: ‘Willstätt′ not the county, this is no city.

    I had problems with this in v1 too and Stiofan has managed this with an overwrite for my site, see here please:

    https://wpgeodirectory.com/support/topic/understanding-openstreetmap-auto-fill-api-and-saving-cities-locationss/

    and here:

    https://wpgeodirectory.com/support/topic/understanding-openstreetmap-auto-fill-api-and-saving-cities-locationss/page/2/

    Now after the update to v2, the address.county is saved as location and this is a bug or is related to the changes of Stiofan in the v1.

    1. How can I change the auto fill to set the right value for the city field on the Add listing form? (address.city or address.village instead of address.county)

    2. How can I change the auto fill for the address field. I want to have it in the German format: address.road address.house_number, address.village (but just if there is an address.city too, otherwise I’ll have the location twice, in the address field and in the city field)

    #527516

    directoryfan
    Expired Member
    Post count: 157
    This reply has been marked as private.
    #527555

    Alex Rollin
    Moderator
    Post count: 27815

    The developers will check into it.

    #527725

    Naveen Giri
    Moderator
    Post count: 1559

    Hi directoryfan,

    Could you please share FTP details in private reply.

    Thanks

    #527736

    directoryfan
    Expired Member
    Post count: 157
    This reply has been marked as private.
    #527737

    directoryfan
    Expired Member
    Post count: 157

    Thank you Naveen for looking into it!

    #528009

    Kiran
    Moderator
    Post count: 7069

    Hi @directoryfan,

    Use following PHP snippet to adjust city for addresses within Germany.

    
    
    /**
     * Adjust city for Germany addresses with OSM.
     */
    function gd_snippet_adjust_geocode_city() {
    ?>
    if ( window.gdMaps == 'osm' ) {
    	if ( getCountryISO == 'DE' && response.address ) {
    		gdaddr = response.address;
    
    		if ( ! gdaddr.city && ! gdaddr.town && gdaddr.village ) {
    			getCity = gdaddr.village;
    			response.city = getCity;
    		}
    	}
    }
    <?php
    }
    add_filter( 'geodir_add_listing_geocode_js_vars', 'gd_snippet_adjust_geocode_city', 30 );

    I have added snippet under Snippets > OpenStreetMap autocomplete search adjust city.

    Please check and let us know.

    Regards,
    Kiran

    #528018

    directoryfan
    Expired Member
    Post count: 157

    Hi @kiranprajapati,

    and thank you Kiran for your great help! The city field is saving now the right data.

    1. You have some php tags in the snippet, is this OK? I have no error in the backend, it is just unusual.

    2. How can I change the address format of the address field, not the city field. Now I have 5 Street – but the German is Street 5, so first is the street and then the street number.

    Thank you so much for your help!
    Marius

    #528025

    Kiran
    Moderator
    Post count: 7069

    1) It is required.

    2) It fill address what it get from the OpenStreetMaps address search response. https://nominatim.openstreetmap.org/search?q=Messingstra%C3%9Fe%2010,%20Legelshurst&format=json&addressdetails=1&limit=1&accept-language=en

    Kiran

    #529948

    directoryfan
    Expired Member
    Post count: 157

    Hi @kiranprajapati,
    and thank you for your help! I’ll try to be more clear about the problem with the German address format for OSM.

    1. Address format for Germany

    Yes, the response is O.K., it is like it should be.

    [
      {
        "place_id": 169981210,
        "licence": "Data © OpenStreetMap contributors, ODbL 1.0. https://osm.org/copyright",
        "osm_type": "way",
        "osm_id": 352879183,
        "boundingbox": [
          "48.5723478",
          "48.5724337",
          "7.9127649",
          "7.9129952"
        ],
        "lat": "48.57238835",
        "lon": "7.912879965448619",
        "display_name": "10, Messingstraße, Willstätt, Ortenaukreis, Baden-Württemberg, 77731, Deutschland",
        "class": "building",
        "type": "yes",
        "importance": 0.22100000000000003,
        "address": {
          "house_number": "10",
          "road": "Messingstraße",
          "village": "Willstätt",
          "county": "Ortenaukreis",
          "state": "Baden-Württemberg",
          "postcode": "77731",
          "country": "Deutschland",
          "country_code": "de"
        }
      }
    ]

    Just that the house number starts the string in the field display_name. But in Germany the house number is after the street name, so how can you change this?

    This is how it should be, after choosing the autocomplete address string:

    address.road address.house_number, address.village

    like in the Nominatin docs: de street_name {street} {house_number} (https://wiki.openstreetmap.org/wiki/Nominatim/Country_Address_Format)

    2. Search restriction and optimization

    Please take a look at the Nominatin API and params: https://nominatim.org/release-docs/develop/api/Search/

    In order to restrict and optimize the search and the country address format (feature request: could be super cool to have these options in the back-end)

    As my project is restricted to one German state how should I use these params for the search query?:

    accept-language='de'
    countrycodes='de'
    viewbox=7.5,47.6,10.5,49.8
    bounded=1

    Please help me, this will be great for different countries, since different countries have different address formats.

    Greetings, Marius

    #530026

    Alex Rollin
    Moderator
    Post count: 27815

    At this time we do not have per-country address formatting. Instead the address field uses a common format. What you are asking for currently requires a customization, but we do plan on looking into this for future versions.

    #530077

    Kiran
    Moderator
    Post count: 7069

    Hi @directoryfan,

    I have opened a task to check it feasible to use address format for different countries.

    See https://github.com/AyeCode/geodirectory/issues/1063

    Kiran

    #533399

    directoryfan
    Expired Member
    Post count: 157

    Hi @kiranprajapati,
    and thank your for your attention and for looking into the address format issue.

    I think the issue with the search restriction and optimization is important for local directories. If someone is searching for a very popular address, then the response from Nominatin API will often not include it in the proposals for automatic completion. Even addresses from other countries are proposed.

    Please take a look at the Nominatin API and params: https://nominatim.org/release-docs/develop/api/Search/

    As my project is restricted to one German state how should I use these params for the search query?:

    accept-language='de'
    countrycodes='de'
    viewbox=7.5,47.6,10.5,49.8
    bounded=1

    to have something like this:

    https://nominatim.openstreetmap.org/search?q=Hauptstra%C3%9Fe%2015&accept-language=de&countrycodes=de&viewbox=7.5,47.6,10.5,49.8&bounded=1&format=json&addressdetails=1

    The JS code is here:

    https://github.com/AyeCode/geodirectory/blob/master/assets/leaflet/osm.geocode.js

    And Stiofan changed it for me in v1. It will be perfect if you could add some backend settings for the advanced search like: countrycodes, viewbox and bounded. Like that, the Nominatin API will respond much faster and the user can use the proposals in case of popular street names in that country or language.

    Please add this as feature request to github or please help me to to customize the osm.geocode.js.

    Greetings

Viewing 13 posts - 1 through 13 (of 13 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket