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 - ต้องการดึงค่าพิกัดละติจูด ลองจิจูด มาสร้างเป็น marker ใน google map แต่ไม่ได้ค่ะ



 

Android - ต้องการดึงค่าพิกัดละติจูด ลองจิจูด มาสร้างเป็น marker ใน google map แต่ไม่ได้ค่ะ

 



Topic : 108175

Guest




Code (Android-Java)
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 com.project.arjj.R;

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 Map extends FragmentActivity implements
	GooglePlayServicesClient.ConnectionCallbacks,
	GooglePlayServicesClient.OnConnectionFailedListener, OnClickListener {
	GoogleMap mMap;
	Marker mMarker;
	Polyline direction;
	LatLng coordinate;
	LocationClient mLocationClient;
	Location mCurrentLocation;

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

		mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).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, 18));
		
			mMarker = mMap.addMarker(new MarkerOptions().position(coordinate).icon(BitmapDescriptorFactory
	                .fromResource(R.drawable.bubble))
	                .draggable(true));
			
			
			
			
		}
	}

	public void onDisconnected() {
	
	}

	public void onClick(View v) {
	
	}
	
	public void showMarker() {
	String url = "http://teawnai.com/travel2/rattana/testrattana.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", c.getString("Id"));
			map.put("Lat", c.getString("Lat"));
			map.put("Long", c.getString("Long"));
			map.put("name", c.getString("name"));
			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("Long");
			
			lat = Double.parseDouble(Lat);
			lng = Double.parseDouble(Long);
			
			mMarker = mMap.addMarker(new MarkerOptions()
					.position(new LatLng(lat, lng))
					.icon(BitmapDescriptorFactory
            .fromResource(R.drawable.bubble)));
			
		}
   
    
    } 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();
	}

}



มันไม่ยอมดึงค่ามาสร้างเป็นตัว marker บนแผนที่ให้ค่ะ ไม่รู้ผิดตรงไหน ผู้รู้ช่วยทีนะค่ะ



Tag : Mobile, Android, JAVA







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2014-05-07 22:54:49 By : sanay View : 1942 Reply : 2
 

 

No. 1



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

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

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

Code (Android-Java)
	public void showMarker() {
	String url = "http://teawnai.com/travel2/rattana/testrattana.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", c.getString("Id"));
			map.put("Lat", c.getString("Lat"));
			map.put("Long", c.getString("Long"));
			map.put("name", c.getString("name"));
			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("Long");
			
			lat = Double.parseDouble(Lat);
			lng = Double.parseDouble(Long);
			
			mMarker = mMap.addMarker(new MarkerOptions()
					.position(new LatLng(lat, lng))
					.icon(BitmapDescriptorFactory
            .fromResource(R.drawable.bubble)));
			
		}


ตอนนี้พวกนี้มันแสดงข้อมูลหรือโหลดจากเว็บได้แล้วหรือยังครับ ลองใช้พวก Log ทำการ Write ค่าดู หรือ Debug ดูได้หรือไม่ ??






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


 

No. 2



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

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

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

ลองศึกษาเพิ่มเติมบทความ Android กับ Google Map ครับ



Android Google Map (Step by Step)

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-11-18 14:15:31 By : mr.win
 

   

ค้นหาข้อมูล


   
 

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