Calculating Distance

I have asked similar question in the past but was not able to complate this task, but now I need to get back to it. I was able to find this page with the example of how to calculate the distance.
In my case this would be a STEP2

This seems to be the simplest method:

  1. Include this line in a header
    [SIZE=13px]<script[/SIZE][SIZE=13px] [/SIZE][SIZE=13px]type[/SIZE][SIZE=13px]=[/SIZE][SIZE=13px]“text/javascript”[/SIZE][SIZE=13px] [/SIZE][SIZE=13px]src[/SIZE][SIZE=13px]=[/SIZE][SIZE=13px]“http://maps.google.com/maps/api/js?sensor=false&v=3&libraries=geometry”[/SIZE][SIZE=13px]></script> 2. Call this JS script to calculate
[/SIZE]   
 [SIZE=13px]google[/SIZE][SIZE=13px].[/SIZE][SIZE=13px]maps[/SIZE][SIZE=13px].[/SIZE][SIZE=13px]geometry[/SIZE][SIZE=13px].[/SIZE][SIZE=13px]spherical[/SIZE][SIZE=13px].[/SIZE][SIZE=13px]computeDistanceBetween [/SIZE][SIZE=13px]([/SIZE][SIZE=13px]latLngA[/SIZE][SIZE=13px],[/SIZE][SIZE=13px] latLngB[/SIZE][SIZE=13px]);[/SIZE]  
 [SIZE=13px]

then this

    var loc1 = new GLatLng(52.5773139, 1.3712427); var loc2 = new GLatLng(52.4788314, 1.7577444); var dist = loc2.distanceFrom(loc1); alert(dist/1000);   

to get the distance [/SIZE]

I need to complete STEP1 which is finding Lat/Long from the given address.
so variables loc1 and loc2 can be filled with appropriate values.

I’m not sure if this URL will help you out,
but here it is: http://www.codexworld.com/get-latitude-longitude-from-address-using-google-maps-api-php/

and here’s the demo: http://demos.codexworld.com/get-latitude-longitude-from-address-using-google-maps-api-php/

Interesting stuff non-the-less.

I’m not sure if this will help, but it’s interesting non-the-less.
Link: http://www.codexworld.com/get-latitude-longitude-from-address-using-google-maps-api-php/
Link: http://demos.codexworld.com/get-latitude-longitude-from-address-using-google-maps-api-php/

I’ve seen that before I posted here but this code for some reason does not work. I guess it is simply outdated. Google changes their API quite often.

If you use the Google Api’s then yes, sometimes you need to change your code. But it’s still the way to go.

Arthur
This is an example that works perfectly. You just need to change locations.

//request the directions
$routes=json_decode(file_get_contents(‘http://maps.googleapis.com/maps/api/directions/json?origin=bomerstraat%2018,%20peer&destination=kievitwijk%2028,%20helchteren&alternatives=true&sensor=false’))->routes;

//sort the routes based on the distance
usort($routes,create_function(’$a,$b’,‘return intval($a->legs[0]->distance->value) - intval($b->legs[0]->distance->value);’));

//print the shortest distance
echo $routes[0]->legs[0]->distance->text;//returns 9.0 km

Larry

Tnx Larry for this useful sample.

OK guys - I thank you for your time but,… either I’m to dumb or you are to smart for me :wink:
Larry you posted some lines of code completely out of the rest of some project which basically tells me nothing. I neither understand this code or know how to implement it. Perhaps for someone who did that 100+ times might seem clear and easy. The problem is that there is no documentation on how to implement any Google API’s into SC. I have seen one webinar about APIs by Marcia but she usually has a tendency to skip things she do not understand herself. I asked her about posting webinar projects on NM site (few months ago) and she promised to do this but of course like everything else - it was just an empty promise.

The way the Google API is implemented on the pages which comply with MVC mode is very different from what’s needed in SC (I know this much). It would be great if someone could provide some samples or tutorials. I’m ready to Offer an SC samples library if there is enough users to post projects. Perhaps if one of you guys is smart enough to make a sample App this could be the first Example to share with others. At this point I do not even know how to )globally) assigns G API libraries to SC ? I saw Marcia used just Copy/Paste approach with only the fragment of code from Google site and created SC library, but the video does not even show what was copied to SC. The main thing (when doing presentations or giving advice and help to others) is to be precise and pay attention to details (and that is what NetMake does not do well at all).
Using Copy/Paste method is very dangerous because the moment the API is changed the whole method might die.

I also tried to use different links in different formats to include Google APIs but so far none of them worked even for super simple things. Perhaps I’m doing something wrong. BTW, I do not want to use JASON, I need to access database directly (read the record, assign values to VARs and pass the m as parameters).

Thanks - Art

Perhaps we could clarify the steps here so other users can benefit from this post:

  1. How to include Google API in SC project (by URL reference) so it can be declared only once per project ?

  2. How to call API method ?

  3. How to pass Variables to the method ?

  4. Working example would be beneficial (if anybody has one please PM me and I will post it on-line available for others)

ok, so after 2 days it looks like either nobody did this, or nobody knows how to do it - right ?
(or perhaps nobody wants to share)

That is simple. If you know how to do it without SC you can do it in SC in a blank app

hirambq - you are super helpful! without you I wouldn’t know this, but next time do not waste your time and space for posts like this one. Piloting a plane is also super easy for those who did that many times.

BTW. Implementing it in SC is not the same as outside. Most examples on-line deal with MVC structure and SC does not support it. API Libraries are referenced by URL and SC does not support it (or there is no info how to do it). I might be wrong on that but it seems that the only way to get any API’s work is to Copy/Paste the API JS code into SC which (if ture) is very, very bad scenario.