• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: create google map two points calculate distance

create google map two points calculate distance 9 years 1 month ago #30408

  • dispatch
  • dispatch's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 16
  • Thank you received: 1
www.rsjoomla.com/forum/search.html?q=goo...ldforums=1&catids=37

Mine: www.rsjoomla.com/forum/37-rsform-pro/244...lculation.html#28614

No answer in over a month

This is the "freshest" mentioning my search of > google maps

www.rsjoomla.com/forum/37-rsform-pro/244...ogle-maps.html#29994

Posted by another user on above: This is one of the mandatory things why I got RSFORM! Pro..

ME TOO !!

1) I need to Create an End User Entry Form with a few fields.

Fields for now = Name, email, (3) Text Fields and then Drop down of Type and then simply enter (2) zip codes and simply have a small map drawn as well as get the mileage

2) Based on TYPE [will have variables assigned] & MILEAGE, I will then need to perform a calculation and provide a SUM to log and display to user, store in database as well as email admin and end user.

3) For now? It will be just QUOTE Amount

4) Data later will then possibly will need EDIT and re-create > NEW SUM

5) At this point? It will then be a "billing form" = Invoice to send via Paypal.

Thank you.
The administrator has disabled public write access.

create google map two points calculate distance 9 years 1 month ago #30410

  • cosmin.cristea
  • cosmin.cristea's Avatar
  • OFFLINE
  • Platinum Boarder
  • Posts: 756
  • Thank you received: 144
Calculating the distance between 2 addresses can be done using the Google Distance Matrix API. This customization will require using the PHP scripts called on form display and the Javascript section (found in the Form Properties).

1st step

Create a new form and create a normal button (for this example i named it search);
Create 2 googlemaps (for this example i named them gmap1 & gmap2)

2nd step

Create a PHP Script called on form process to calculate the distance, this can be done like so (read comments)
$action = JRequest::getWord('action'); // we will need a parameter to run the script
if ($action == "ajax") { // if condition is met, run the script
 
	$origin = $_POST['origin']; // get the origin
	$destination = $_POST['destination']; // get the destination
 
 
	$distance = file_get_contents("https://maps.googleapis.com/maps/api/distancematrix/json?origins=".$origin."&destinations=".$destination); // build the URL according to the API
 
	$distance = json_decode($distance); // decode the response from JSON
 
	print_r($distance->rows[0]->elements[0]->distance->text);die(); // print the result so we can catch it in the AJAX call
 
}


3rd. step

Head over to the Javascript section found in the Form Properties and we need to request the calculation from google. Insert the following snippet (read the comments)
<script>
jQuery(document).ready(function(){ // we wait until DOM is ready
	jQuery('#search').click(function(){ // we bind a function when clicking the button we added earlier
 
		origin = jQuery('#gmap1').val(); //  we grab the value from the first googlemap
		origin = origin.replace(/\s+/g, '+'); // remove white spaces
		origin = origin.replace(/,/g , ""); // remove commas
		destination = jQuery('#gmap2').val(); //  we grab the value from the second googlemap
		destination = destination.replace(/\s+/g, '+'); // remove white spaces
		destination = destination.replace(/,/g , ""); // remove commas
 
		jQuery.ajax({ // we build the AJAX request
				type:"POST", 
 				url:"index.php?option=com_rsform&formId=3&action=ajax", // Due to Cross Origin Request Blocks we need to call it sever side (this is the reason why we created the PHP script called on form display ) please make sure you use the correct formId (the ID of this form)
				data: {origin, destination}, // we send the origin and destination information to the script we already crated 
				success: function(results) {
					alert(results); // on success we alert the distance
				}
		});
 
	});
 
})
 
</script>

Please note that this is only an example on how you can perform some basic operations with the Google Maps, it should be treated as an example and not a solution. PS: You can find the sample form attached (simply restore it through the Back-up Restore Functionality).
Map Distance Calculation Form
My help is not official customer support. To receive your support, submit a ticket by clicking here
Last Edit: 9 years 1 month ago by cosmin.cristea.
The administrator has disabled public write access.

create google map two points calculate distance 9 years 2 days ago #30767

Hi,

I'm trying your code, it's very interesting but when i install your exemple form i get a 'Uncaught SyntaxError: Unexpected token ,'
at " type:"GET", " line..
Do you think is a jquery conflict ? i test many things but it will not disappear.
Have you an idea?

Thx
Have a nice day
The administrator has disabled public write access.

create google map two points calculate distance 9 years 2 days ago #30768

  • cosmin.cristea
  • cosmin.cristea's Avatar
  • OFFLINE
  • Platinum Boarder
  • Posts: 756
  • Thank you received: 144
Make sure you edit the formId to match your current one in the AJAX function.

Let me know if it works.
My help is not official customer support. To receive your support, submit a ticket by clicking here
The administrator has disabled public write access.
The following user(s) said Thank You: BenoitMPmedias

create google map two points calculate distance 9 years 2 days ago #30769

  • cosmin.cristea
  • cosmin.cristea's Avatar
  • OFFLINE
  • Platinum Boarder
  • Posts: 756
  • Thank you received: 144
For your scenario, you will have to use formId=5

Let me know if it works!
My help is not official customer support. To receive your support, submit a ticket by clicking here
The administrator has disabled public write access.
The following user(s) said Thank You: BenoitMPmedias

create google map two points calculate distance 9 years 2 days ago #30776

  • dispatch
  • dispatch's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 16
  • Thank you received: 1
Hi Cosmin and sorry for my late reply, I am subscribed to this topic...but did not get a notification of new reply?

Just happened to pop on. As my time to dedicate to what I thought was "built in" like so many things...is limited to work with. I came to RSForm Pro, as the way it read? Was all easier...as I had been using Fabrik and it my objective was to "Plug and Play" as to not have to deal with coding at all...

I guess I am curious as to how all the rest of "time" and websites [even shopping carts now] have much simpler gathering and producing? Over the years have done it.

Don't get me wrong? You've come a long way with this :-) So thanks !!

Jim
The administrator has disabled public write access.

create google map two points calculate distance 9 years 2 days ago #30777

Hi Thx for fast answer :)

But i still have the same error and my formId=6 :s

Thx again :)
The administrator has disabled public write access.

create google map two points calculate distance 9 years 2 days ago #30782

[up] Didn't know if u see my message thx to tel me if u have an idea ! regards
Last Edit: 9 years 2 days ago by BenoitMPmedias. Reason: up
The administrator has disabled public write access.

create google map two points calculate distance 9 years 1 day ago #30792

  • cosmin.cristea
  • cosmin.cristea's Avatar
  • OFFLINE
  • Platinum Boarder
  • Posts: 756
  • Thank you received: 144
From my tests I figured out (or I presume) the Id of your form is 5 (not 6). Try it and let me know (the ID should match the id of the form, you can see the ID in the Manage Forms section of RSForm!Pro - Last Column)
My help is not official customer support. To receive your support, submit a ticket by clicking here
The administrator has disabled public write access.
The following user(s) said Thank You: BenoitMPmedias

create google map two points calculate distance 9 years 1 day ago #30795

Thx for your reply !!!

i found an other solution only in js and it works like charm.

Thx for all
Have a nice day :)
The administrator has disabled public write access.

create google map two points calculate distance 9 years 1 day ago #30796

  • cosmin.cristea
  • cosmin.cristea's Avatar
  • OFFLINE
  • Platinum Boarder
  • Posts: 756
  • Thank you received: 144
If you have a better solution, please consider sharing it with the community. Thank you in advance
My help is not official customer support. To receive your support, submit a ticket by clicking here
The administrator has disabled public write access.

create google map two points calculate distance 8 years 11 months ago #30910

  • dispatch
  • dispatch's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 16
  • Thank you received: 1
BenoitMPmedias wrote:
Thx for your reply !!!

i found an other solution only in js and it works like charm.

Thx for all
Have a nice day :)

Happy Easter, would you mind sharing the solution please?

Jim
re: If you have a better solution, please consider sharing it with the community. Thank you in advance

I am sorry, I must ask > How come developers are unable to ? Since the mid to late 1990's Mapquest has been able to do this, then Google, yahoo and even has been integrated into Joomla shopping cart Virtuemart 1.5 years ago about by a 3rd party. [distance and time etc between Point A and Point B]

forum.virtuemart.net/index.php?topic=120179.0

Sorry to have to post this, but as I have mentioned I have purchased this with the expectations that I could create my form, and when the end user has entered "2 street addresses" RSFormsPro could do the work for me, with what existing Mapping and mileage by using rods and driving time without having to hire a coder?

LoL

Again, Happy Easter.. Maybe the Easter Bunny will bring this someday? I can not afford to wait for Santa Claus :woohoo:
Last Edit: 8 years 11 months ago by dispatch.
The administrator has disabled public write access.

create google map two points calculate distance 8 years 7 months ago #32087

  • dispatch
  • dispatch's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 16
  • Thank you received: 1
UNFINISHED BIZ.

I am NOT RENEWING!!

You're too lazy?
The administrator has disabled public write access.

create google map two points calculate distance 6 years 2 months ago #37838

  • tom_vanbrabant
  • tom_vanbrabant's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 14
  • Thank you received: 4
Any updates for this solution?
This fix does not seam to work anymore. :blink:

Thanks

** CORRECTION: It works! **
Last Edit: 6 years 1 month ago by tom_vanbrabant.
The administrator has disabled public write access.

create google map two points calculate distance 5 years 9 months ago #38236

  • SNortham
  • SNortham's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 3
Is anyone able to offer coding support for this?

I require the output to be provided in miles (not KM)

and

the output to appear in a text box within the form rather than a pop-up

:)
The administrator has disabled public write access.

create google map two points calculate distance 5 years 9 months ago #38238

  • dispatch
  • dispatch's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 16
  • Thank you received: 1
As "DID" I also, the way they worded it, made one think they had it coded.

And easily implemented...so I let my subscription lapse, it's been years now, so that tells me a waste of $$$
The administrator has disabled public write access.

create google map two points calculate distance 5 years 9 months ago #38239

  • SNortham
  • SNortham's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 3
I am happy to pay for support as this is outside the scope of the normal RSForms etc, just thought would try here first before seeing if can get someone on freelancer etc :)
The administrator has disabled public write access.

create google map two points calculate distance 4 years 6 months ago #39476

  • dispatch
  • dispatch's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 16
  • Thank you received: 1
Very Disappointed myself
The administrator has disabled public write access.

create google map two points calculate distance 4 years 6 months ago #39479

  • tom_vanbrabant
  • tom_vanbrabant's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 14
  • Thank you received: 4
Very poor way to work with Google API. There are much better forms out there.
Seams RSJoomla does not care for what clients desire.

5 years ... still no decent solution :dry: :sick:
The administrator has disabled public write access.
The following user(s) said Thank You: dispatch
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!