corsasport.co.uk
 

Corsa Sport » Message Board » Off Day » Geek Day » Need a form making... Half way there... need some Java guys in here!


New Topic

New Poll
  <<  1    2  >> Subscribe | Add to Favourites

You are not logged in and may not post or reply to messages. Please log in or create a new account or mail us about fixing an existing one - register@corsasport.co.uk

There are also many more features available when you are logged in such as private messages, buddy list, location services, post search and more.


Author Need a form making... Half way there... need some Java guys in here!
Gary
Premium Member

Avatar

Registered: 22nd Nov 06
Location: West Yorkshire
User status: Offline
2nd Nov 10 at 19:21   View Garage View User's Profile U2U Member Reply With Quote

I need a form that will query google maps or whatever that will find out the distance between a set postcode and a user imported ones. Times the milage by a number, add another number and then relay that information back to the user.

Will be a fitting charge calculator based on distance from me.

Not got a clue how to do this. Anyone got any ideas?

[Edited on 03-11-2010 by glb]
adiohead
Member

Registered: 28th Sep 01
User status: Offline
2nd Nov 10 at 19:48   View User's Profile U2U Member Reply With Quote

Download google to your hard drive
noshua
Member

Registered: 19th Nov 08
User status: Offline
2nd Nov 10 at 20:38   View User's Profile U2U Member Reply With Quote

I'd start by looking at the Google Maps API

http://code.google.com/apis/maps/documentation/mapsdata/

[Edited on 02-11-2010 by noshua]
noshua
Member

Registered: 19th Nov 08
User status: Offline
2nd Nov 10 at 20:44   View User's Profile U2U Member Reply With Quote

Found this in about 5 minutes

http://briancray.com/wp-content/uploads/2009/04/distance.html

View>Source

or

http://briancray.com/2009/04/01/how-to-calculate-the-distance-between-two-addresses-with-javascript-and-google-maps-api/

[Edited on 02-11-2010 by noshua]
ed
Member

Registered: 10th Sep 03
User status: Offline
2nd Nov 10 at 21:24   View User's Profile U2U Member Reply With Quote

They're straight line calculations and won't work using postcodes. To get driving directions you need to use the directions API and to use postcodes you need access to the Royal Mail postcode file.
ed
Member

Registered: 10th Sep 03
User status: Offline
2nd Nov 10 at 21:29   View User's Profile U2U Member Reply With Quote

Just had a little look, you can use the AJAX API to geocode UK postcodes accurately.
Gary
Premium Member

Avatar

Registered: 22nd Nov 06
Location: West Yorkshire
User status: Offline
2nd Nov 10 at 21:45   View Garage View User's Profile U2U Member Reply With Quote

Could prob work with the straight line distances. Unless anyone can find anything that does actual milage.

Ed, using the google API and Royal Mail sounds complicated.

Could maybe use the straight line distances in a banding. 0-50miles 50-100 miles etc.

Would just be talking that script and adding a few bits i guess.

Thi shit is behond me. Might have a play but cant see me getting my head round it.
ed
Member

Registered: 10th Sep 03
User status: Offline
2nd Nov 10 at 21:54   View User's Profile U2U Member Reply With Quote

The second link noshua posted has this link in it: http://briancray.com/2009/06/23/calculate-driving-distance-google-maps-api/

Seems to work on full addresses, but postcodes have always been a bit more tricky.

Google provide this directions API:

http://code.google.com/apis/maps/documentation/directions/

Here's an example for postcode geocoding:

http://www.tomanthony.co.uk/blog/geocoding-uk-postcodes-with-google-map-api/


Google Maps stuff isn't too tricky once you get into it. It's fairly complex if you haven't worked with external API's before though!
Gary
Premium Member

Avatar

Registered: 22nd Nov 06
Location: West Yorkshire
User status: Offline
2nd Nov 10 at 22:00   View Garage View User's Profile U2U Member Reply With Quote

I didnt know what API was untill now so its a bit bemusing. I think i need a few hours on the PC going through this.

Would have thought somthing like this would be availabe FOC somewhere. Sp,e guy was talking about it on the ZenCart forums but dont think anything came of it.
Gary
Premium Member

Avatar

Registered: 22nd Nov 06
Location: West Yorkshire
User status: Offline
3rd Nov 10 at 08:59   View Garage View User's Profile U2U Member Reply With Quote

I've used what you posted and sorted my own Google API code etc. Ive put it up online @ gasworksair.co.uk

Now i need to remove the 1st address box and make it pre-set. Then add some extra coding so it dosent show the distances etc, It shows the 'distance * 0.4 + 55'


Any ideas how?
Gary
Premium Member

Avatar

Registered: 22nd Nov 06
Location: West Yorkshire
User status: Offline
3rd Nov 10 at 09:23   View Garage View User's Profile U2U Member Reply With Quote

Fuigured out the Distance * 0.4 +55 bit.

Just need to remove the Address 1 box and make it a fixed value
Gary
Premium Member

Avatar

Registered: 22nd Nov 06
Location: West Yorkshire
User status: Offline
3rd Nov 10 at 09:28   View Garage View User's Profile U2U Member Reply With Quote

Done that too. Just changed the input type from text to hidden.

Quite easy this Java lark!
Gary
Premium Member

Avatar

Registered: 22nd Nov 06
Location: West Yorkshire
User status: Offline
3rd Nov 10 at 09:39   View Garage View User's Profile U2U Member Reply With Quote

Can anyone advise on what i need to do to round up the outputted number to 2DP?

http://gasworksair.co.uk/
ed
Member

Registered: 10th Sep 03
User status: Offline
3rd Nov 10 at 12:16   View User's Profile U2U Member Reply With Quote

Nice work so far!

To round a number to two DP you do the following:

var price=150.56789823475890324;
var priceRound=Math.round(price*100)/100;

alert(priceRound);
Gary
Premium Member

Avatar

Registered: 22nd Nov 06
Location: West Yorkshire
User status: Offline
3rd Nov 10 at 13:25   View Garage View User's Profile U2U Member Reply With Quote

Where abouts do I need to insert that code? Just with the rest of the Var's?
Gary
Premium Member

Avatar

Registered: 22nd Nov 06
Location: West Yorkshire
User status: Offline
3rd Nov 10 at 14:00   View Garage View User's Profile U2U Member Reply With Quote

done it.

put

var TotalRound=Math.round(Total*100)/100;

and made it show TotalRound instead of total.
Gary
Premium Member

Avatar

Registered: 22nd Nov 06
Location: West Yorkshire
User status: Offline
3rd Nov 10 at 14:17   View Garage View User's Profile U2U Member Reply With Quote

is up at www.gasworksair.co.uk/shop/quote


would be nice to have a couple of radio buttons that add on extra cost dependant on which one is selected.
Dom
Member

Registered: 13th Sep 03
User status: Offline
3rd Nov 10 at 14:20   View User's Profile U2U Member Reply With Quote

quote:
Originally posted by glb
is up at www.gasworksair.co.uk/shop/quote


would be nice to have a couple of radio buttons that add on extra cost dependant on which one is selected.


You've got .htaccess authetication on
Gary
Premium Member

Avatar

Registered: 22nd Nov 06
Location: West Yorkshire
User status: Offline
3rd Nov 10 at 14:32   View Garage View User's Profile U2U Member Reply With Quote

admin, admin

sorry
ed
Member

Registered: 10th Sep 03
User status: Offline
3rd Nov 10 at 14:47   View User's Profile U2U Member Reply With Quote

Use this for your postcode input:

<input type="text" name="address2" placeholder="Enter Your Postcode" />

Just a bit neater
Dom
Member

Registered: 13th Sep 03
User status: Offline
3rd Nov 10 at 14:50   View User's Profile U2U Member Reply With Quote

also you NEED to display a google map if you're using their API (could stick a link to a popout div etc)
Gary
Premium Member

Avatar

Registered: 22nd Nov 06
Location: West Yorkshire
User status: Offline
3rd Nov 10 at 14:57   View Garage View User's Profile U2U Member Reply With Quote

quote:
Originally posted by Dom
also you NEED to display a google map if you're using their API (could stick a link to a popout div etc)


Will sort that when ive got it working

Plus i have no idea how to do it
Gary
Premium Member

Avatar

Registered: 22nd Nov 06
Location: West Yorkshire
User status: Offline
3rd Nov 10 at 14:57   View Garage View User's Profile U2U Member Reply With Quote

quote:
Originally posted by ed
Use this for your postcode input:

<input type="text" name="address2" placeholder="Enter Your Postcode" />

Just a bit neater



Whats the difference between Placeholder and Value?
Gary
Premium Member

Avatar

Registered: 22nd Nov 06
Location: West Yorkshire
User status: Offline
3rd Nov 10 at 14:58   View Garage View User's Profile U2U Member Reply With Quote

Placeholder removes the 'Enter your Postcode' text from the box.
noshua
Member

Registered: 19th Nov 08
User status: Offline
3rd Nov 10 at 16:14   View User's Profile U2U Member Reply With Quote

Rather than Search I'd have Calculate

  <<  1    2  >>
New Topic

New Poll

  Related Threads Author Forum Replies Views Last Post
What Java Compiler Is Standard? Mikorsa16v Geek Day 2 1303
13th Mar 03 at 16:02
by Mikorsa16v
 
Anyone know anything about Java Script/HTML ed Geek Day 6 1000
14th Feb 04 at 18:16
by Joff
 
How do you use the java multi upload thing jr General Chat 23 1342
25th Jun 06 at 14:35
by Gaz
 
URGENT HELP: Any Java experts? (Updated) steve101 Geek Day 13 571
1st May 07 at 00:43
by Dom
 

Corsa Sport » Message Board » Off Day » Geek Day » Need a form making... Half way there... need some Java guys in here! 28 database queries in 0.0157599 seconds