Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > Mobile > Mobile Forum > Android - GPS + Location Manager (อยากทราบ การหา เวลา m/s ที่ GPS อ่านได้ กับ องค์ศาที่เปลี่ยนแปลงไป)



 

Android - GPS + Location Manager (อยากทราบ การหา เวลา m/s ที่ GPS อ่านได้ กับ องค์ศาที่เปลี่ยนแปลงไป)

 



Topic : 099552



โพสกระทู้ ( 6 )
บทความ ( 0 )



สถานะออฟไลน์




ขยายความ จากโค้ดด้านล่าง เป็นการอ่านค่า GPS ที่จับได้แล้วสแดงออกทาง TextView
อยากทราบถึงเวลาที่ GPS อ่านค่าได้ เก็บค่าเป็น Array แสดงออกทาง TextView




Code (Android-Java)
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.provider.Settings;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.widget.TextView;
import android.widget.Toast;

public class Main extends Activity {
	LocationManager lm;
	TextView textLatitude, textLongitude, text_Kg_h;
	Double temp;
	
		public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		textLatitude = (TextView) findViewById(R.id.textLatitude);
		textLongitude = (TextView) findViewById(R.id.textLongitude);
		text_Kg_h = (TextView) findViewById(R.id.text_kg_h);
		lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

		Criteria criteria = new Criteria();
		criteria.setAccuracy(Criteria.ACCURACY_FINE);
		criteria.setAltitudeRequired(false);
		criteria.setBearingRequired(false);
	}

	public void onResume() {
		super.onResume();
		setup();
	}

	public void onStart() {
		super.onStart();
		boolean gpsEnabled, networkEnabled;
		gpsEnabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);

		if (!gpsEnabled) {
			networkEnabled = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
			if (!networkEnabled) {
				Intent intent = new Intent(
						Settings.ACTION_LOCATION_SOURCE_SETTINGS);
				startActivity(intent);
			}
		}
	}

	public void onStop() {
		super.onStop();
		lm.removeUpdates(listener);
	}

	public void setup() {
		
		lm.removeUpdates(listener);
		String latitude = "ยังไม่ได้รับค่า latitude";
		String longitude = "ยังไม่ได้รับค่า longitude";

		Location networkLocation = requestUpdatesFromProvider(
				LocationManager.NETWORK_PROVIDER, "ไม่สามารถเชื่อมต่อ Network ได้");
		if (networkLocation != null) {
			latitude = String.format("%.7f", networkLocation.getLatitude());
			longitude = String.format("%.7f", networkLocation.getLongitude());
		}

		Location gpsLocation = requestUpdatesFromProvider(
				LocationManager.GPS_PROVIDER, "GPS ยังไม่ถูกเปิดใช้งาน นะค่ะ");

		if (gpsLocation != null) {
			latitude = String.format("%.7f", gpsLocation.getLatitude());
			longitude = String.format("%.7f", gpsLocation.getLongitude());
			
		}

		textLatitude.setText(latitude);
		textLongitude.setText(longitude + "\n" + temp );
		}

	public Location requestUpdatesFromProvider(final String provider,
			String error) {
		Location location = null;
		if (lm.isProviderEnabled(provider)) {
			lm.requestLocationUpdates(provider, 1000, 10, listener);
			location = lm.getLastKnownLocation(provider);
		} else {
			Toast.makeText(this, error, Toast.LENGTH_LONG).show();
		}
		return location;
	}

	public final LocationListener listener = new LocationListener() {
		public void onLocationChanged(Location location) {
			textLatitude.setText(String.format("%.7f", location.getLatitude()));
			textLongitude.setText(String.format("%.7f", location.getLongitude()));
                        // 
			temp = location.getSpeed() ; // อ่านค่า m/s เก็บไว้ใน temp ผมเข้าใจถูกหรือเปล่าครับ
                        //						
		}




Tag : Mobile, Android, Tablets, Mobile









ประวัติการแก้ไข
2013-08-24 15:45:35
2013-08-24 21:32:39
2013-08-24 21:33:51
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2013-08-24 15:40:54 By : auttpon View : 1623 Reply : 1
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

ใช้การเก็บลงใน ArrayList น่ะครับ มันสามารถที่จะเพิ่มได้เรื่อย ๆ ครับ

Code (Java)
ArrayList<String> myArrList = new ArrayList<String>();
myArrList.add("Belgium");
myArrList.add("France");
myArrList.add("Italy");
myArrList.add("Germany");


แสดงผล

Code (Java)
for (String temp : myArrList) {
	//temp;
}







แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-08-27 06:27:54 By : mr.win
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : Android - GPS + Location Manager (อยากทราบ การหา เวลา m/s ที่ GPS อ่านได้ กับ องค์ศาที่เปลี่ยนแปลงไป)
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 05
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่