2013-07-26 12 views
0

這是我的數學:如何在PHP中將正數添加到負數中?

$range = 0.43218; 
$this->location['longitude'] = -78.852972745895; 
$this->location['latitude'] = 42.879424080703; 

$minlong = $this->location['longitude']-$range; 
$maxlong = $this->location['longitude']+$range; 
$minlat = $this->location['latitude']-$range; 
$maxlat = $this->location['latitude']+$range; 

但我結束了這一點:

$minlong = -79.285152745895; 
$maxlong = -78.420792745895; 
$minlat = 42.447244080703; 
$maxlat = 43.311604080703; 

我試着用兩個原始緯度和經度的範圍內就結了,誰能幫我我的數學。我一整天都在用數字工作,他們在殺我!

+0

然後我用這些來從數據庫中的數據,我的SQL是SELECT * FROM'Stores'那裏('Longitude' BETWEEN「 -79.285152745895'和'-78.420792745895')和('Latitude'BETWEEN'42.444242480703'和'43.31604080703')但是這不會返回任何結果,儘管應該有3個結果 – ldrrp

+4

對我來說看起來不錯。你當前的結果有什麼問題? – Mike

+0

繼承人鏈接到我的3個結果,應該顯示http://ft.trillian.im/bf33102d41b540ba92d5daba6e50e69018e5dc8a/6ipqYDjaNCHU9UuzI0It1gyTcB1eH.jpg – ldrrp

回答

1

找到我的答案,好像我必須只需撥動他們

if($this->location['longitude'] < 0){ /* Flip if negative */ 
    $minlong = $this->location['longitude']+$range; 
    $maxlong = $this->location['longitude']-$range; 
}else{ 
    $minlong = $this->location['longitude']-$range; 
    $maxlong = $this->location['longitude']+$range; 
} 
if($this->location['latitude'] < 0){ /* Flip if negative */ 
    $minlat = $this->location['latitude']+$range; 
    $maxlat = $this->location['latitude']-$range; 
}else{ 
    $minlat = $this->location['latitude']-$range; 
    $maxlat = $this->location['latitude']+$range; 
} 
+3

所以「min」意思是「更靠近赤道或素數子午線」,而不是數值上更低。 – Barmar