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,025

HOME > Mobile > Mobile Forum > รบกวนหน่อยครับ Android Map โชว์พิกัดตัวเองได้แต่เรียกค่าโชว์จุดที่2 จาก databaseไม่ได้



 

รบกวนหน่อยครับ Android Map โชว์พิกัดตัวเองได้แต่เรียกค่าโชว์จุดที่2 จาก databaseไม่ได้

 



Topic : 090066



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



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




Code (Android-Java)
package com.example.mylocation;

import java.text.NumberFormat;
import java.util.List;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.provider.Settings;
import android.view.KeyEvent;
import android.widget.TextView;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;

import com.example.mylocation.Main;
import com.example.mylocation.R;
import com.example.mylocation.Main.MyItemizedOverlay;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.MyLocationOverlay;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
import android.app.ProgressDialog;
import android.database.Cursor;
import android.database.sqlite.SQLiteCursor;
import android.database.sqlite.SQLiteDatabase;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.net.ParseException;
import android.util.Log;

public class Main extends MapActivity {
	LocationManager myLocationManager;
	LocationListener myLocationListener;
	MyLocationOverlay myLocationOverlay;
	MapView mapView;
	MapController mc;
	TextView tv;

	MyItemizedOverlay itemizedOverlay;
	Drawable drawable;
    List<Overlay> mapOverlays;
    String latt;
    String lonn ;
	String imei2;
	String bus;
	JSONArray jArray;
	String result = null;
	InputStream is = null;
	StringBuilder sb = null;
	ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		tv = (TextView) findViewById(R.id.textView1);
		mapView = (MapView) findViewById(R.id.mapview);
		mc = mapView.getController();
		mc.setZoom(15);
		mapView.setBuiltInZoomControls(true);
		mapView.setSatellite(false);		
		
		myLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
		myLocationListener = new MyLocationListener();

		// ตรวจสอบว่าเปิด GPS หรือไม่
		if (!isGpsEnable()) {
			Intent intent = new Intent(Settings.ACTION_SECURITY_SETTINGS);
			startActivity(intent);

		}
		myLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
				0, 0, myLocationListener);
		myLocationOverlay = new MyLocationOverlay(this, mapView);
		myLocationOverlay.enableMyLocation();
		myLocationOverlay.getOrientation();
		myLocationOverlay.enableCompass();// แสดงเข็มทิศ
		mapView.getOverlays().add(myLocationOverlay);// แสดงบนแผนที่
		mapView.invalidate();
	}

	public boolean onCreateOptionsMenu(Menu main) {
		MenuInflater menuInflater = getMenuInflater();
		menuInflater.inflate(R.menu.main, main);
		return true;
	}

	public boolean onOptionsItemSelected(MenuItem item)// เมนูู
	{

		switch (item.getItemId()) {

		case R.id.menuItem1:
			Toast.makeText(Main.this, "เคลียร์สายรถประจำทาง", 3000).show();
			return true;

		case R.id.menuItem2:
			Toast.makeText(Main.this, "เมนูแผนที่", Toast.LENGTH_SHORT).show();
			if (mapView.isSatellite() == true) {
				mapView.setSatellite(false);
			}
			return true;

		case R.id.menuItem3:
			Toast.makeText(Main.this, "แผนที่ดาวเทีนม", Toast.LENGTH_SHORT)
					.show();
			if (mapView.isSatellite() == false) {
				mapView.setSatellite(true);
			}
			return true;

		case R.id.menu_bus66:
			Toast.makeText(Main.this, "สาย 66", 3000).show();
			return true;

		default:
			return super.onOptionsItemSelected(item);
		}
	}

	@Override
	protected boolean isRouteDisplayed() {
		return false;
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// Handle the back button
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			new AlertDialog.Builder(this)
					.setMessage("คุณต้องการออกจากโปรแกรม")
					.setCancelable(false)
					.setPositiveButton("Yes",
							new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface dialog,
										int id) {
									Main.this.finish();
								}
							}).setNegativeButton("No", null).show();
			return true;
		} else {
			return super.onKeyDown(keyCode, event);
		}

	}

	public boolean isGpsEnable() {
		boolean isgpsenable = false;
		String provider = Settings.Secure.getString(getContentResolver(),
				Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
		if (!provider.equals("")) { // GPS is Enabled
			isgpsenable = true;
		}
		return isgpsenable;
	}

	// ///////// locationListener class ////////
	private class MyLocationListener implements LocationListener {
		public void onLocationChanged(Location argLocation) {
			GeoPoint gpsPoint = new GeoPoint(
					(int) (argLocation.getLatitude() * 1000000),
					(int) (argLocation.getLongitude() * 1000000));
			mc.animateTo(gpsPoint);

			NumberFormat nf = NumberFormat.getInstance();
			nf.setMinimumFractionDigits(2);
			nf.setMaximumFractionDigits(6);
			String lat = nf.format(argLocation.getLatitude());
			String lon = nf.format(argLocation.getLongitude());

			tv.setText(latt + "," + lonn);
		}

		public void onProviderDisabled(String provider) {
		}

		public void onProviderEnabled(String provider) {
		}

		public void onStatusChanged(String provider, int status, Bundle extras) {
		}

	}// end locationListener class

	public void LoadData() {


		// http post
		try {
			HttpClient httpclient = new DefaultHttpClient();
			HttpPost httppost = new HttpPost("http://192.168.209.183/server/data.php");
			httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
			HttpResponse response = httpclient.execute(httppost);
			HttpEntity entity = response.getEntity();
			is = entity.getContent();
		} catch (Exception e) {
			Log.e("log_tag", "Error in http connection" + e.toString());
		}
		// convert response to string
		try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(
					is, "iso-8859-1"), 8);
			sb = new StringBuilder();
			sb.append(reader.readLine() + "\n");

			String line = "0";
			while ((line = reader.readLine()) != null) {
				sb.append(line + "\n");
			}
			is.close();
			result = sb.toString();
		} catch (Exception e) {
			Log.e("log_tag", "Error converting result " + e.toString());
		}
		// paring data
		try {
			jArray = new JSONArray(result);
			JSONObject json_data = null;
			for (int i = 0; i < jArray.length(); i++) {
				json_data = jArray.getJSONObject(i);
				latt = json_data.getString("latt");
				lonn = json_data.getString("lonn");
				imei2 = json_data.getString("imei2");
				bus = json_data.getString("bus");

				List<Overlay> mapOverlays = mapView.getOverlays();
				drawable = this.getResources().getDrawable(R.drawable.bus);
				itemizedOverlay = new MyItemizedOverlay(drawable);
				double lat = Double.parseDouble(latt);
				double lon = Double.parseDouble(lonn);

				GeoPoint point = new GeoPoint((int) (lat * 1E6),
						(int) (lon * 1E6));
				OverlayItem overlayitem = new OverlayItem(point, "bus", imei2);
				itemizedOverlay.addOverlay(overlayitem);
				mapOverlays.add(itemizedOverlay);

				mc = mapView.getController();
				mc.setCenter(point);
				tv.setText(latt + "," + lonn);

				// Overlay code

			}
		} catch (JSONException e1) {
			Toast.makeText(getBaseContext(), "No City Found", Toast.LENGTH_LONG)
					.show();
		} catch (ParseException e1) {
			e1.printStackTrace();
		}
	}

	// Customized MyItemizedOverlay class
	class MyItemizedOverlay extends ItemizedOverlay<OverlayItem> {
		// Define an OverlayItem ArrayList, in which we'll put each of
		// the OverlayItem objects we want on our map
		private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();

		public MyItemizedOverlay(Drawable defaultMarker) {
			super(boundCenterBottom(defaultMarker));
		}

		protected OverlayItem createItem(int i) {
			return mOverlays.get(i);

		}

		public int size() {
			return mOverlays.size();
		}

		protected boolean onTap(int index) {
			OverlayItem item = mOverlays.get(index);
			// Title
			String title = item.getTitle();
			// Snippet
			String snippet = item.getSnippet();
			Toast.makeText(Main.this, title + "\n" + snippet, Toast.LENGTH_LONG)
					.show();
			return true;
		}

		public void addOverlay(OverlayItem overlay) {
			mOverlays.add(overlay);
			populate();
		}
	}
}




Tag : MySQL, Android, JAVA







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2013-01-31 02:18:37 By : lonalosolo View : 1277 Reply : 2
 

 

No. 1



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

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

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

Quote:
http://192.168.209.183/server/data.php


เรียกไม่ได้นี่คือไม่มีค่าหรือข้อมูลไม่มาให้ครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-01-31 12:39:50 By : mr.win
 


 

No. 2



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



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


ข้อมูลใน ไฟล์ php มีครับ โชว์แล้วได้ครับ แต่พอลงในมือถือมันก็เปิดไม่ได้ ครับ ทำไงดี เหมือนมันเรียกไม่ได้อะครับ


ประวัติการแก้ไข
2013-01-31 17:02:07
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-01-31 17:01:09 By : lonalosolo
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : รบกวนหน่อยครับ Android Map โชว์พิกัดตัวเองได้แต่เรียกค่าโชว์จุดที่2 จาก databaseไม่ได้
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 อัตราราคา คลิกที่นี่