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 - ปัดหมุด Map v2 จาก JSON ครับ // ไม่ขึ้น marker ตำแหน่งที่ดึงมาจาก JSON แต่ขึ้นตำแหน่งปัจจุบัน



 

Android - ปัดหมุด Map v2 จาก JSON ครับ // ไม่ขึ้น marker ตำแหน่งที่ดึงมาจาก JSON แต่ขึ้นตำแหน่งปัจจุบัน

 



Topic : 109250



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



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




จากที่เคยเห็น admin ตอบเรื่องปักหมุดจาก JSON อะครับ ลองแก้ๆดู มันขึ้นแค่หมุดของตำแหน่งปัจจุบันของเรา

ค่าที่เรา get มาเป็น double ของ lat กับ lng มันไม่ขึ้นหมุดอะครับ

Code (Android-Java)
package th.ac.src.project.finder;


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

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesClient;
import com.google.android.gms.location.LocationClient;
import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.maps.model.Polyline;



import android.R.string;
import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;

public class mapTest extends FragmentActivity implements
	GooglePlayServicesClient.ConnectionCallbacks,
	GooglePlayServicesClient.OnConnectionFailedListener, OnClickListener {
	GoogleMap mMap;
	Marker mMarker;
	Polyline direction;
	LatLng coordinate;
	LocationClient mLocationClient;
	Location mCurrentLocation;

	private String Lat, Long;
	//private String Id;
	Double lat;
	Double lng;
	protected void onCreate(Bundle savedlnstanceSrate) {
		super.onCreate(savedlnstanceSrate);
		setContentView(R.layout.activity_map);

		mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.mapB)).getMap();

		mLocationClient = new LocationClient(this, this, this);
		mMap.setMyLocationEnabled(true);
		mMap.getUiSettings().setCompassEnabled(true);
		mMap.getUiSettings().setRotateGesturesEnabled(true);
}


	protected void onStart() {
		mLocationClient.connect();
		super.onStart();
	}


	protected void onStop() {
		mLocationClient.disconnect();
		super.onStop();

	}

	public void onConnectionFailed(ConnectionResult result) {

	}

	public void onConnected(Bundle connectionHint) {
		if(mLocationClient.isConnected()){
			mCurrentLocation = mLocationClient.getLastLocation();
			coordinate = new LatLng(mCurrentLocation.getLatitude(), mCurrentLocation.getLongitude());
			mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(coordinate, 15));
		
			mMarker = mMap.addMarker(new MarkerOptions().position(coordinate).icon(BitmapDescriptorFactory
	                .fromResource(R.drawable.pin4))
	                .draggable(true));
			
			
			
			
		}
	}

	public void onDisconnected() {
	
	}

	public void onClick(View v) {
	
	}
	
	public void showMarker() {
		String url = "http://103.7.56.128/~patsakorn/select_host.php";
		Log.i("oooooo", "success");
		   try {
		   	JSONArray data = new JSONArray(getJSONUrl(url));
			
		   	final ArrayList<HashMap<String, String>> MyArrList = new ArrayList<HashMap<String, String>>();
			HashMap<String, String> map;
			
			for(int i = 0; i < data.length(); i++){
		           JSONObject c = data.getJSONObject(i);
				map = new HashMap<String, String>();
				
				map.put("id_host", c.getString("id_host"));
				map.put("lat", c.getString("lat"));
				map.put("lng", c.getString("lng"));
				map.put("name_host", c.getString("name_host"));
				//map.put("image", c.getString("image"));
				//map.put("information", c.getString("information"));
				//map.put("imageinfo", c.getString("imageinfo"));
				MyArrList.add(map);
			
				
				Lat = map.get("lat");
				Long = map.get("lng");
				
				lat = Double.parseDouble(Lat);
				lng = Double.parseDouble(Long);
				
				mMarker = mMap.addMarker(new MarkerOptions()
						.position(new LatLng(lat, lng)));
				
				
			}
   
    
    } catch (JSONException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
    }
    
}
	public String getJSONUrl(String url) {
		StringBuilder str = new StringBuilder();
		HttpClient client = new DefaultHttpClient();
		HttpGet httpGet = new HttpGet(url);
		try {
			HttpResponse response = client.execute(httpGet);
			StatusLine statusLine = response.getStatusLine();
			int statusCode = statusLine.getStatusCode();
			if (statusCode == 200) { // Download OK
				HttpEntity entity = response.getEntity();
				InputStream content = entity.getContent();
				BufferedReader reader = new BufferedReader(new InputStreamReader(content));
				String line;
				while ((line = reader.readLine()) != null) {
					str.append(line);
				}
			} else {
				Log.e("Log", "Failed to download file..");
			}
		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return str.toString();
	}

}




Tag : Mobile, MySQL, Android, JAVA, Mobile







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2014-06-17 14:40:44 By : nickiestar View : 1311 Reply : 1
 

 

No. 1



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

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

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

Code
Lat = map.get("lat"); Long = map.get("lng"); lat = Double.parseDouble(Lat); lng = Double.parseDouble(Long); mMarker = mMap.addMarker(new MarkerOptions() .position(new LatLng(lat, lng)));


Debug ดูแล้วครับ ว่ามันเข้าตัวนี้หรือไม่






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-06-18 09:06:02 By : mr.win
 

   

ค้นหาข้อมูล


   
 

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