Skip Navigation

[Resolved] Adresses and distances in Toolset Maps

This support ticket is created 4 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 10 replies, has 2 voices.

Last updated by jurgenK-2 4 years, 9 months ago.

Assisted by: Christian Cox.

Author
Posts
#1525415
Rombus_screen1.JPG

Tell us what you are trying to do?
I import custom type posts "Jobs" with WP all Import. this works well. The import also contains an address in the form "postcode city". Postcode and city is imported into an address field. This ist shown in the custom post and toolset is providing the coordinates as shown in screenshot rombus_screen1.jpg.

When trying to display job results on maps or trying to list jobs in distance to some location I have some strange behaviour., In the first place there where no results when using the address. the I found out that I have to open the job post and save it manually, so I get some results, but not all.

First question is: can I automatically open and save all my custom posts at the same time, so the coordinates will be saved? Or is the another way to get the coordinates with WP all Import?

Second question: The following code in views is giving no result, even where there are results:
[toolset-maps-distance-value location='Bad Homburg, Deutschland' postmeta='wpcf-adresse'] km from Bad Homburg, <br>[toolset-maps-distance-value location='Magdeburg, Deutschland' postmeta='wpcf-adresse-lat-long'] km from Magdeburg
Please see last column in this page
hidden link

Third question: not all manually saved jobs are shown in this map:
hidden link
using this code:
[wpv-layout-start]
[wpv-items-found]
[wpv-map-render map_id="map-1"][/wpv-map-render]
<!-- wpv-loop-start -->
<wpv-loop>
[wpv-map-marker map_id='map-1' marker_id='marker-5' marker_field='wpcf-adresse'][/wpv-map-marker]

Fourth question: on the bottom of the page I am using a distance search. There you can see all manually saved jobs (7 at the moment). this is working but not showing the distances. Any idea whats going wrong here?

When starting to import addresses, I had several address fields. Afterwards I deleted the or made the type "single line". The deleted one is still selectable in Views..

I would be very happy getting help to get this working.

Thank you.

Jürgen

#1525653

First question is: can I automatically open and save all my custom posts at the same time, so the coordinates will be saved? Or is the another way to get the coordinates with WP all Import?
See this other ticket for some explanation: https://toolset.com/forums/topic/custom-search-including-map-distance-filter-not-working-as-expected/

The problem here is that imported addresses have not been geocoded, so you must trigger that process before the addresses can be "found" by a distance search. You can trigger that process by simply opening the post in wp-admin (which displays the address on a small map, caching the address). You need not save the post, simply opening it in wp-admin is sufficient. Fine for a small amount of posts, but not for a large amount or for an automated import process that runs periodically. Another way to trigger geocoding is to create another map View that has no distance filter and loads all the new addresses as markers. Visit the map on the front-end of the site to trigger the geocode process and cache the addresses for use by a distance filter. Depending on the number of imported addresses, you may need to load the map multiple times to geocode all the addresses, because Google imposes limits on the number of addresses you can geocode per second.

When starting to import addresses, I had several address fields. Afterwards I deleted the or made the type "single line". The deleted one is still selectable in Views..
Please go to Toolset > Custom Fields and click "Post Field Control" at the bottom of the page. Make sure the field is completely deleted here, or it may continue to appear in the select options.

For your second, third, and fourth questions I would need to take a quick look in wp-admin to see how things are configured. Can you provide login credentials in the private fields here? Then I'll be able to give you some feedback.

Also note that this marker ID in your loop will not be unique:

[wpv-map-marker map_id='map-1' marker_id='marker-5' marker_field='wpcf-adresse'][/wpv-map-marker]

I generally use the map ID and post ID shortcode to make the marker ID unique per map, like so:

[wpv-map-marker map_id='map-1' marker_id='marker-[wpv-post-id]-map-1' marker_field='wpcf-adresse'][/wpv-map-marker]

I add the map ID in case for some reason I decide to use more than one map on the same page. This is a simple way to help prevent duplicate marker IDs.

#1527427

Loading in a map is not sufficient to generate coordinates as you can see here: hidden link and here hidden link Only after opening and saving a job markers will be shown on the map.
After reimport, which is supposed to be every hour automatically, the coordinates are lost.
I see what you mean, I assumed you had validated, geocoded addresses to import. It turns out the fully geocoded addresses are not exactly the same as the imported values. Notice that the mappable addresses contain more complete address values. For example, see the first result in the View below the map. The address field value that was imported seems to be:

39104 Magdeburg

Notice in the View, there is no country name. This address corresponds to the post here:
hidden link
When you open the post in wp-admin, Google Maps Autocomplete changes the imported address to be something mappable. In the US, for example, when I edit the post I see it changes to:

39104 Magdeburg, Germany

Notice the country name is included here, but not identical to the imported address value. Is it possible to import the country name with the other address information during the import and reimport processes?

#1528335

Hello Christian,

great, this is a big step in the solution of my issues. The geocoding is quite sensitive to the format of the address...

After importing again with the country name in the address, most of the markers were shown on the map and the distance search began working.

 39104 Magdeburg, Deutschland

But still I have some questions. On this page hidden link I implemented a view with a distance search and some parameter tests.

What I found is that the field wpcf-adresse needs one specific version of the address to work. Other versions won't be accepted.

 61348 Bad Homburg vor der Höhe, Deutschland

will bring results both on the distance search and on the map.

The distance search and the map marker will not work using

 61348 Bad Homburg, Deutschland

(which is also part of the import data and the more commonly used version).

 Bad Homburg vor der Höhe, Deutschland

or

Hamburg, Deutschland

will bring no result in the distance search, because the post code is missing. Still it is suggested from Google in the Show results within 30 km of "" field.

How can we make this more user friendly?

You can check this in view "Jobliste mit Suche" and template "Loop item in Liste" which is shown on hidden link

#1528623

Are you saying you would like to display one address but use a different address for geocoding? I guess you could accomplish that by importing two custom fields - one full address for geocoding and another partial address for display. I'm not sure I understand the question though, sorry! Could you explain a bit more?

#1528683

Yes, I can explain further. Please try to use the distance search and you will understand, the field in "Show results within 30 km of "xxx" .

If you search for the following, the distance search will not work

Bad Homburg, Germany
61348 Bad Homburg, Germany
Bad Homburg vor der Höhe, Germany

The distance search will only work with

61348 Bad Homburg vor der Höhe, Germany

You will see that in the output in the right column of the results:
If there is "19,3 km from toolset_maps_distance_center" the distance could be calculated.
If there ist " km from toolset_maps_distance_center" the distance could NOT be calculated.

This is generated in the view with

[toolset-maps-distance-value origin_source='url_param' postmeta='wpcf-adresse'] km from toolset_maps_distance_center

This also effects the import with WP All import.
If I import the following, it will not be shown on the map

61348 Bad Homburg, Germany

If I import the following, it will be shown on the map

61348 Bad Homburg vor der Höhe, Germany

This is too case sensitive to work practically.

Do you understand me now?

#1530827
Screen Shot 2020-02-27 at 11.42.43 AM.png

Okay I understand that the address format is quite sensitive. You mentioned that the longer version of the address is not user-friendly. What is the problem, exactly? Are you concerned that Users will not be able to type the address precisely or correctly? I understand this concern, and the solution depends on how or where the address is originally entered. Someone is typing addresses somewhere, right? When they type an address, they should be forced to enter valid data in a user-friendly way. The best way is to use the Google Maps Javascript API with Places Autocomplete to capture addresses. Otherwise, there is no way to guarantee the address is mappable and will work with a distance filter.

If you create a post in wp-admin, the autocomplete address field is already provided by Toolset Maps. You must select an address from a list of suggestions, then this address is guaranteed to be mappable and to work with distance filters.

If Users create posts using Toolset Forms, the autocomplete address field is already provided by Toolset Forms. The User must select an address from the autocomplete suggestions, then the address is guaranteed to be mappable and to work with distance filters.

One problem remains - imported posts and addresses. If the address is typed into a 3rd-party application, that application should use the Google Maps API with Places Autocomplete:
https://developers.google.com/maps/documentation/javascript/places-autocomplete
See the screenshot here. When I type 61348 bad homburg, Google returns a list of autocomplete suggestions. Notice the first suggestion is the full, precise address. So this is a user-friendly way to ensure addresses are mappable.

I hope this helps you improve the experience of collecting address data and using that data to map posts and calculate distances.

#1531669

Thank you for you in depth explanation.

My point is that I cannot use every address from Google Autocomplete, but only one specific form of addresses. All the above mentioned addresses come from Google Autocomplete.

I did further tests and found that all addresses from Google Autocomplete do not work in the distance search except these seven addresses I imported in toolset in their specific form.

61184 Karben, Germany
61213 Bad Nauheim, Germany

are working.

50668 Köln, Germany
48291 Telgte, Germany
Ebertplatz 1, 50668 Köln, Deutschland

are not working.

All come from Google Autocomplete.

Do you see this effect, too?

#1535605

Any news about this issue?

#1535987
Screen Shot 2020-03-02 at 10.50.26 AM.png

I'm running a few tests but there seems to be an issue with your API key. In Toolset > Settings > Maps tab, there is a button you can use to check the API. I'm getting an error message that your API key has restrictions. I suggest adding a second API key without restrictions, since the second API key will never be exposed on the front-end of the site. That second API key can then be used for server-side requests without restrictions.

#1537323

Ok that was the problem...I remove the referer restriction for the Google API key, and the geolocation search works. Thank you for the hint.

Unfortunately, I could not add a second key right now, beacuse Google wants some authentification information, I do not understand right now. (hidden link) But thats not your business...I will find out and do some more tests.

So far many thanks for your help.