php写point,geoPHP point in polygon

i need some help, google makes me sad

I got polygon http://geojson.io/#id=gist:anonymous/069b8a955897723ca256&map=4/58.75/48.03

And it covering a lot.

And i got geoPHP library https://github.com/phayes/geoPHP

Which got methods contains, covers, coveredBy...

And everything is normal, except that point like 74.224074, 96.428248 is always false for methods contains,coveredBy,covers, etc for this polygon. But it must be true.

Please, tell me why. I got a headache.

OR

Tell me please, how check that the lat lng is inside polygon. I tested about 3 libraries in perl and php, making my own code, etc... But the right results i got only from google containsLocation in javascript. But i have to use it on server side, not in browser. If there any chance to use containsLocation in nodejs it would be very nice.

Thank you

A little code for geoPHP:

$a='JSON FROM LINK';

$b=geoPHP::load("POINT(74.224074 96.428248)","wkt");

$a=geoPHP::load($a, 'json');

$result=$a->contains($b);

var_dump($result);

And it will be false

EDIT:

I think i got it.

GeoJson making coordinates in wrong way, longtitude, latitude. But it must be latitude, longtitude.

Will try and then write here if it works

ANSWER:

Use this www.birdtheme.org/useful/v3tool.html to make polygon on maps. It making it in right way(latitude,longtitude)

Working code for geoPHP:

include_once('geoPHP.inc');

$addr=file_get_contents('https://maps.googleapis.com/maps/api/geocode/json?address='.urlencode($_GET['address']).'&sensor=false');

foreach($addr->{results} as $addr1)

{

if(array_key_exists("geometry",$addr1)){

$lat=$addr1->{geometry}->{location}->{lat};

$lng=$addr1->{geometry}->{location}->{lng};

break;

}

}

$point1 = geoPHP::load("POINT($lat $lng)","wkt");

$ya200=geoPHP::load("POLYGON((41.51 12.3, 38.27 28.83, 32.55 41.84, 27.6 55.55, 29.54 71.37, 33.43 83.32, 36.6 94.92, 36.6 99.49, 35.17 111.45, 32.55 124.8, 35.17 130.78, 39.64 142.73, 43.58 152.58, 45.83 166.29, 56.17 163.83, 63.07 159.26, 68.66 154.69, 72.18 148.71, 75.93 140.63, 78.49 129.02, 80.3 114.26, 80.98 100.2, 81.2 87.54, 80.87 73.83, 79.62 59.41, 76.27 40.43, 71.07 28.13, 67.2 23.2, 63.55 20.04, 59.01 17.23, 54.16 15.12, 48.46 13.36,41.51 12.3))","wkt");

var_dump($ya200->contains($point1));

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值