1

I'm not entirely sure if this is possible, or the right way to go about this, however here goes.

I have a front end entry form that members use to create entries. These entries contain location data. I'm looking at using a maps plugin but nothing out there supports front end directly. I'm currently testing Squarebit Maps. (Smartmap is next!)

Now, from checking out the db, Squarebit Maps stores it's field data in the craft_content table in a format like so:

{"mapLat":"50.89150121867578","mapLng":"-1.4487441291137202","mapZoom":"15","pinLat":"50.89150121867578","pinLng":"-1.4487441291137202","__model__":"Craft\\SquareBitMaps_MapModel"}

I was wondering, if I included a map for users to choose a location within the front end form using something like Geocomplete could I pass through the lat & long in a hidden field to the squarebit field?

Hope that makes sense?

2
  • Let me know when you get to Smart Map... this would actually be pretty easy to do. ;)
    – Lindsey D
    Commented Dec 30, 2015 at 6:16
  • Well, tested this with morning, and I can pass the data with a value like 50.89150121867578|-1.4530571212096688|14|50.89150121867578|-1.4487441291137202 straight to the field and it sets the map correctly. This is good, obviously just need to join these values together when the form is submitted. Good to know. Lindsey, I'd be happy to hear any suggestions as to how I would achieve this using Smartmap. I have my copy you sent ready for testing! :)
    – shorn
    Commented Dec 30, 2015 at 8:58

1 Answer 1

1

It's probably too late to help the OP (sorry @shorn), but here's how you would pull this off with Smart Map...

Add the Address field on the front-end.

<label>Street Address</label>
<input type="text" name="fields[myAddressField][street1]" value="">

<label>Apartment or Suite</label>
<input type="text" name="fields[myAddressField][street2]" value="">

<label>City</label>
<input type="text" name="fields[myAddressField][city]" value="">

<label>State</label>
<input type="text" name="fields[myAddressField][state]" value="">

<label>Zip Code</label>
<input type="text" name="fields[myAddressField][zip]" value="">

<label>Country</label>
<input type="text" name="fields[myAddressField][country]" value="">

<label>Latitude</label>
<input type="text" name="fields[myAddressField][lat]" value="">

<label>Longitude</label>
<input type="text" name="fields[myAddressField][lng]" value="">

Then, you can inject the lat and lng values using JavaScript. Since you're doing that dynamically, you could even make those inputs hidden.

That's it!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.