20.11.2016 Views

ANDROID APP

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

การใช้ Google Maps<br />

275<br />

กรรมวิธี: การกำหนดข้อความแจ้งเตือนเมื่อออกจากพื้นที่ที่กำหนดไว้<br />

คลาส LocationManager มีเมธอดที่ใช้ในการทำงานประเภทข้อความแจ้งเตือนเมื่อออกจาก<br />

พื้นที่ที่กำหนดไว้ (Proximity) ซึ่งจะแสดงข้อความเตือนเมื่อมีการเคลื่อนย้ายอุปกรณ์ออกนอกพื้นที่ที่<br />

กำหนดไว้ โดยเราจะกำหนดขอบเขตของพื้นที่ดังกล่าวด้วยค่าละติจูดและลองติจูด และค่าของระยะ<br />

ทางซึ่งมีหน่วยเป็นเมตร ส่วนข้อความเตือนจะกำหนดไว้ใน PendingIntent ซึ่งจะแสดงเมื่อผู้ใช้งาน<br />

ออกนอกพื้นที่ที่กำหนด นอกจากนี้เรายังสามารถกำหนดระยะเวลาที่จะแสดงข้อความเตือนได้ด้วย<br />

ชุดคำสั่งที่ 10.14 จะแสดงขั้นตอนการทำงานตามรายละเอียดที่กล่าวมาแล้ว<br />

ชุดคำสั่งที่ 10.14 ตัวอย่างของการกำหนดข้อความแจ้งเตือนเมื่อออกจากพื้นที่ที่กำหนดไว้<br />

double mlatitude=35.41;<br />

double mlongitude=139.46;<br />

float mRadius=500f; // in meters<br />

long expiration=-1; //-1 never expires or use milliseconds<br />

Intent mIntent = new Intent("You entered the defined area");<br />

PendingIntent mFireIntent<br />

= PendingIntent.getBroadCast(this, -1, mIntent, 0);<br />

mLocationManager.addProximityAlert(mlatitude, mlongitude,<br />

mRadius, expiration, mFireIntent);

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!