distance through

Events happening in the community are now at Drupal community events on www.drupal.org.
marinv's picture

Hello

I am using node_load in order to calculate the distance of a hotel to the city center.
There are two content types: "hotel", which contains the fields latitude, longitude and city;
The other content type is "city" with city name as title and the fields latitude and longitude, the coordinates of the city center (thanks to maxmind.com geolite dates};

I am using the following script:

<?php
$title
=$data->node_title;
$city = $data->node_data_field_hid_field_city_value;
$k = $data->node_data_field_hid_field_latitud_value;
$l = $data->node_data_field_hid_field_longitude_value;

$node = node_load(array('title' => $city));
$m=$node->field_lat[0]['value'];
$n=$node->field_lng[0]['value'];
$k = $k/57.29577951;
$l = $l/57.29577951;
$m = $m/57.29577951;
$n = $n/57.29577951;
//convert all to radians: degree/57.29577951

if ($k == $m && $l == $n ){
$dist = 0;
}

else if ( (
sin($k)* sin($m)+ cos($k)* cos($m)* cos($l-$n)) > 1){
$dist = 3963.1* acos(1);//
}

else{
$dist = 3963.1* acos(sin($k)<em>sin($m)+ cos($k)</em> cos($m)* cos($l-$n));
}

$dist = $dist*1.6;

if (
$dist < 30) {
printf ('%0.2f', $dist);
echo
" km to city center";
echo
'<?b>';
}
?>

The problem is when there are many cities with the same name; the script stops to the first one.
I suppose I should use "for each" command, in order to find the right city, but to be honest I do not know how.

Please help!

Comments

calculate distance between 2 addresses using geo modules

auy1jll's picture

Hello,
I am a newbie,
how can I achieve this?
similar to goole map, I want to accept an address say: 162 summer st, Somerville Ma, (input form filed)
and a destination say Logan international airport (input form filed)
the result I want to use to calculate distance by say another value to get rates for the cost of trip using taxi.

is there some good semertan that can show me how to do that in Drupal 7. thanks in advance

Location and Mapping

Group organizers

Group categories

Wiki type

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: