Page 1 of 1

[SOLVED] Lat/Long Multiple different numbers same result?

Posted: Tue Mar 02, 2010 1:37 pm
by kzenman
I'm a little confused by this...ok very confused and have tried everything that I know of to get it to work.

The script is a distance measuring for point A to B

The problem is when multiplying the values it gives the same result?

Here is the code

Code: Select all

 
while( $i <= $count-1){ 
 
 
 
$lat_to = $xml->comp[$i]->address->latitude;
$long_to = $xml->comp[$i]->address->longitude;
 
print "lat_to=".$lat_to." and lat_to * 180 =".$lat_to = round($lat_to * 180,6);
print "long_to=".$long_to." and long_to * 180 =".$long_to * 180;
 
 
 
//distance($lat_from, $long_from, $lat_to, $long_to, $dist);
 
 
print $xmlout .=("<marker nr=\"m".$m."\" category=\"zillow\" address=\"".$xml->comp[$i]->address->street."\" name=\"".$xml->comp[$i]->address->street."\" price=\"".number_format($xml->comp[$i]->lastSoldPrice)." on ".$xml->comp[$i]->lastSoldDate."\" lat=\"".$xml->comp[$i]->address->latitude."\" lng=\"".$xml->comp[$i]->address->longitude."\" yrbuilt=\"".$xml->comp[$i]->yearBuilt."\" estimate=\"".$xml->comp[$i]->zestimate->amount."\" beds=\"".$xml->comp[$i]->bedrooms."/".$xml->comp[$i]->bathrooms."\"  sqft=\"".$xml->comp[$i]->finishedSqFt."\" dist=\"".$xml->comp[$i]->zestimate->valueChange."\" />\n");
 
$lat_to = '';
$long_to = '';
 
$i++;
$m++;
} 
return; 
 
 
Here is the result:
lat_to=33.478081 and lat_to * 180 =5940
long_to=-111.930272 and long_to * 180 =-19980
lat_to=33.46323 and lat_to * 180 =5940
long_to=-111.927663 and long_to * 180 =-19980
lat_to=33.464058 and lat_to * 180 =5940
long_to=-111.930228 and long_to * 180 =-19980
lat_to=33.459373 and lat_to * 180 =5940
long_to=-111.931393 and long_to * 180 =-19980
lat_to=33.483078 and lat_to * 180 =5940
long_to=-111.913447 and long_to * 180 =-19980

You can see the before (green)(lat_to=) then after it's multiplied * 180(red)
I left the round() with and without for showing purposes.

Any Ideas?

Thanks in advance

-Ken

Re: Lat/Long Multiple different numbers same result?

Posted: Tue Mar 02, 2010 3:42 pm
by AbraCadaver
I'm assuming you're using simplexml? The properties aren't what you think they are. Do a var_dump($lat_to) to see it. Then you'll probably want:

Code: Select all

$lat_to = (float)$xml->comp[$i]->address->latitude;
$long_to = (float)$xml->comp[$i]->address->longitude;
Or this will work, but it won't actually be a float as in the previous example. It will be a string, but the calculation should work:

Code: Select all

$lat_to = sprintf("%f", $xml->comp[$i]->address->latitude);
$long_to = sprintf("%f", $xml->comp[$i]->address->longitude);

Re: Lat/Long Multiple different numbers same result?

Posted: Tue Mar 02, 2010 4:00 pm
by kzenman
Thanks AbraCadaver!!!

Works perfectly. I'm guessing that you had the same issue at some point using simplexml? :P

Best!

-Ken