Skip Navigation

[Resolved] Add pin to the map by click, set default center position of map, translate field

This support ticket is created 3 years, 6 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

Author
Posts
#2091531

Tell us what you are trying to do? Set a default position form map in post creation CRED form and enable setting position by click to the map and then drag.

So I need to use this for the marker:

function initMarkers( map ) {

var marker;

google.maps.event.addListener(map, 'click', function(event) {
placeMarker(event.latLng);
});

function placeMarker(location) {

if (marker == null)
{
marker = new google.maps.Marker({
position: location,
map: map,
draggable:true,
animation: google.maps.Animation.DROP,
title:"Drag me!"
});

function handleDrag(event) {
updateFields(event.latLng)
}

marker.addListener("drag", handleDrag)
marker.addListener("dragend", handleDrag)
}
else
{
marker.setPosition(location);
}

updateFields(location);
}

}

And this to center the map where I need it:
/**
* centerMap
*/
function centerMap( map ) {
var location = {lat: 49.81749199999999, lng: 15.472962}; // Czech republic
map.setCenter(location);
}

Is there any documentation that you are following? I have done it before with Google maps javascript API, but not with cred shortcode...

Is there a similar example that we can see? Yes I built it with Fluent Forms, but I need to use the Toolset instead hidden link

What is the link to your site? hidden link

Also, I need to enable In Map zoom with CTRL + mousewheel.

#2091535

I also need to set the zoom to the other level.

#2092319

Hi,

Thank you for contacting us and I'd be happy to assist.

The Address field in Toolset Forms, works differently from what you're planning to achieve, so this will require a fair amount of customization.

Although, 1-1 customization of this scale is beyond the scope of support that we can provide over the forum, we do our best to guide in the right direction, whenever possible.

To add some custom solution, you'll first need to understand what happens in the background.

When a user types some address in the field in the form, it is Geocoded and the lat/long coordinates are filled in the fields below, and the location is plotted on the map.
( screenshot: hidden link )

On submission, the human-readable address is stored as a custom field value with the created post in the respective address field, whereas the lat/long coordinates are stored in the central dedicated table "toolset_maps_address_cache".

Based on this, the best way to achieve what you're planning would be to hide the original Toolset Address and lat/long fields and map and add a custom map where the user can select a location on. The selected location can then be filled in the respective hidden Toolset fields for the human-readable address as well as the lat/long coordinates.

This way, when the form will be submitted, the location data will be processed as a regular entry in the address field.

I hope this helps and for more personalized assistance around custom code, you can also consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/

regards,
Waqar

#2096715

Hello, I am using your standard Map field now, it is nice. But I still need to use the same settings for map, which is avaible in Toolset Views - Zoom, double click to zoom , etc... How can I do that?

#2097977

Thanks for the update.

I see the Toolset address field and the map on the form at /vlozit-vyskyt-karase/ page and features like controls to zoom in/out and double click to zoom in are working on it.

Can you please share some more information about what is missing? You're welcome to share a screencast/video of what you see on your screen.

#2098461

So I need the default zoom when user opens page with form where is set default value to czech republic to be level 7.

I also need to enable the "CTRL + mousewheel to zoom" + two fingers pinch to zoom with tuchpad (both these works with map block in views)

#2101031

Any news?

#2101099

Thank you for waiting.

I've performed some testing and research and can confirm that the map shown in the form is initiated differently from the one shown in views.

We have an internal ticket around this where it was pointed out that the way the this autocomplete map field is currently initiated, it cannot be altered later and will require changes in our code to facilitate that.

I've added your voice to that internal ticket and you're also welcome to submit a feature request to make this address field map more customizable:
https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/

Until then, to achieve something similar, you'll need to go with the suggestions from my earlier message.
( ref: https://toolset.com/forums/topic/add-pin-to-the-map-by-click-set-default-center-position-of-map-translate-field/#post-2092319 )

#2101273

Okay, I will create mine own map then and I will inject the GPS data to the original toolset fields with javascript. Or is it possible only to use filter while saving form to save the values to the right fields?

#2101275

I would love to create 2 generic fields - latitude/longtitude and when form is saved -> save them to the GPS lat/lng on custom map field. Is it possible?

#2101289

I made my own solution hidden link Thank you!