내 데이터베이스에있는 위도와 경도 값을 가진 여러 마커를 표시하려고하지만 문제는지도에서 하나의 마커 만 표시한다는 것을 의미합니다.지도를 통해 다중 마커를 표시하는 방법
public class Map extends Activity implements OnClickListener {
TextView Test;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.maptest);
status();
}
public void status() {
int locationCount =locationCount() ;
for(int i=0;i<locationCount;i++)
{
double Latt = Lat();
double Lngg = Lng();
Test=(TextView)findViewById(R.id.test);
String lat = new Double(Latt).toString();
String lng = new Double(Lngg).toString();
Test.setText(lng+ lat);
}
}
public static String convertStreamToString(InputStream is)
{
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
}
catch (IOException e) {
e.printStackTrace();
}
finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return sb.toString();
}
public static double Lng()
{
try
{
DefaultHttpClient httpClient=new DefaultHttpClient();
//Connect to the server
HttpGet httpGet=new HttpGet("http://10.0.2.2:51220/Service1.svc/Lng");
//Get the response
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
InputStream stream=httpEntity.getContent();
//Convert the stream to readable format
String result= convertStreamToString(stream);
if(result.charAt(1)=='1')
{
return 1;
}
else
{
return 0;
}
}
catch(Exception e)
{
return 0;
}
}
public static double Lat()
{
try
{
DefaultHttpClient httpClient=new DefaultHttpClient();
//Connect to the server
HttpGet httpGet=new HttpGet("http://10.0.2.2:51220/Service1.svc/Lat");
//Get the response
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
InputStream stream=httpEntity.getContent();
//Convert the stream to readable format
String result= convertStreamToString(stream);
if(result.charAt(1)=='1')
{
return 1;
}
else
{
return 0;
}
}
catch(Exception e)
{
return 0;
}
}
public static int locationCount()
{
try
{
DefaultHttpClient httpClient=new DefaultHttpClient();
//Connect to the server
HttpGet httpGet=new HttpGet("http://10.0.2.2:51220/Service1.svc/locationCount");
//Get the response
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
InputStream stream=httpEntity.getContent();
//Convert the stream to readable format
String result= convertStreamToString(stream);
if(result.charAt(1)=='1')
{
return 1;
}
else
{
return 0;
}
}
catch(Exception e)
{
return 0;
}
}
}`
EDIT1
괜찮 이것은이다 : 조건이 참 PLZ 나에게 여기
지도
에 마커 여러 위도의 가치와 LNG 어떻게 보여줄 수있는 솔루션을 제공한다 나의 코드 10.0.2.2:51220/Service1.svc/getLat 의 출력output:
<ArrayOfTrafficConditions>
<TrafficConditions>
<Lat>27.0006748</Lat>
<Latitude>27.0006748</Latitude>
</TrafficConditions>
<TrafficConditions>
<Lat>64.700064</Lat>
<Latitude>64.700064</Latitude>
</TrafficConditions></ArrayOfTrafficConditions>
이 난 그냥 내 안드로이드 응용 프로그램에하지 만 위도 긴 값을 전달하려는
namespace JSONSample
{
public class DataAccess
{
SqlConnection con;
public DataAccess()
{
con = new SqlConnection("Data Source=SE7EN-PC;Initial Catalog=Demo;Integrated Security=True");
}
public List<TrafficConditions> getLat()
{
List<TrafficConditions> Lat= new List<TrafficConditions>();
{
con.Open();
SqlCommand command = new SqlCommand("SELECT DISTINCT Latitude FROM TrafficConditions ", con);
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
TrafficConditions loc = new TrafficConditions();
loc.Latitude = Convert.ToDouble(reader["Latitude"]);
Lat.Add(loc);
}
return Lat.ToList();
}
}
public List<Conditions> getLng()
{
List<Conditions> Lng = new List<Conditions>();
{
con.Open();
SqlCommand command = new SqlCommand("SELECT DISTINCT Longitude FROM TrafficConditions", con);
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
Conditions loc = new Conditions();
loc.Longitude = Convert.ToDouble(reader["Longitude"]);
Lng.Add(loc);
}
return Lng.ToList();
}
}
webserivce의 C# 코드입니다 전체 JSON은
EDIT2
값이지도 활동에 대한 내 실제 코드 죄송
public class MapActivity extends FragmentActivity {
GoogleMap map;
ArrayList<LatLng> markerPoints;
ArrayList<LatLng> marker;
StatusClass gsp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
// Initializing
markerPoints = new ArrayList<LatLng>();
marker = new ArrayList<LatLng>();
// Getting reference to SupportMapFragment of the activity_main
SupportMapFragment fm = (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
// Getting Map for the SupportMapFragment
map = fm.getMap();
if(map!=null){
// Enable MyLocation Button in the Map
map.setMyLocationEnabled(true);
Get();
}
}
public void Get() {
Calendar c1 = Calendar.getInstance();
SimpleDateFormat sdf1 = new SimpleDateFormat("d/M/yy h:m:s a");
String strdate1 = sdf1.format(c1.getTime());
GPSTracker gps = new GPSTracker(MapActivity.this);
gps.canGetLocation();
double Latitude = gps.getLatitude();
double Longitude = gps.getLongitude();
// Adding new item to the ArrayList
markerPoints.add(new LatLng(Latitude,Longitude));
// Creating MarkerOptions
MarkerOptions options = new MarkerOptions();
// Setting the position of the marker
options.position(new LatLng(Latitude,Longitude));
options.title(strdate1+"");
//options.snippet(Timestemp()+ " last updated");
/**
* For the start location, the color of marker is GREEN and
* for the end location, the color of marker is RED.
*/
if(markerPoints.size()>=1){
options.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE));
}
// Add new marker to the Google Map Android API V2
map.addMarker(options);
}
public ArrayList<Double> FromJSONtoArrayListLat() {
ArrayList<Double> ListLat = new ArrayList<Double>();
try {
// Replace it with your own WCF service path
URL json = new URL("http://10.0.2.2:51220/Service1.svc/getLat");
URLConnection jc = json.openConnection();
BufferedReader reader = new BufferedReader(new InputStreamReader(jc.getInputStream()));
String line = reader.readLine();
JSONObject jsonResponse = new JSONObject(line);
JSONArray jsonArray = jsonResponse.getJSONArray("getLat");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jObject = (JSONObject)jsonArray.get(i);
// "FullName" is the property of .NET object spGetPersonsResult,
// and also the name of column in SQL Server 2008
ListLat.add(jObject.getDouble("Latitude"));
}
reader.close();
} catch(Exception e){
Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show();
}
return ListLat;
}
public ArrayList<Double> FromJSONtoArrayListLng() {
ArrayList<Double> ListLng = new ArrayList<Double>();
try {
// Replace it with your own WCF service path
URL json = new URL("http://10.0.2.2:51220/Service1.svc/getLng");
URLConnection jc = json.openConnection();
BufferedReader reader = new BufferedReader(new InputStreamReader(jc.getInputStream()));
String line = reader.readLine();
JSONObject jsonResponse = new JSONObject(line);
JSONArray jsonArray = jsonResponse.getJSONArray("getLng");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jObject = (JSONObject)jsonArray.get(i);
// "FullName" is the property of .NET object spGetPersonsResult,
// and also the name of column in SQL Server 2008
ListLng.add(jObject.getDouble("Longitude"));
}
reader.close();
} catch(Exception e){
Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show();
}
return ListLng;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
이제이 코드에서 위도와 경도 값을 가져 와서 여러 마커를 표시하는 방법은 무엇입니까? u는 나에게 모든
괜찮아요하지만 다른 위도와 위도와 함께 내 데이터베이스에 저장된 http를 통해 여러 마커를 표시하고 싶습니다 내 코드가 뭐가 잘못 됐는지를 지적 할 수 있을까요? 그것의 일을 잘하지만 단지 하나의 마커를 보여주는 – Yumna
@Yumna, for (int i = 0; i
Janpan