안녕하세요.
지금 티맵에 특정 값을 지정해주는 부분을 저의 데이터 베이스에서 가져온 값으로 채우고 싶습니다.
아래의 첫번째는 데이터베이스 가져오기 소스이고,
두번째는 티맵 소스입니다.
질문입니다.
1. 티맵java에서 위도, 경도 좌표를 지정해주는 부분을 데이터베이스에서 가져온 값으로 지정하고 싶습니다.
2. 티맵java에서 위도, 경도 좌표 지정 부분을 데이터베이스에서 가져온 여러 값들을 for 문으로 돌려 한번에 여러개의 마커를 찍고 싶습니다.
3. 티맵 좌표는 Double 형식을 이용한다고 알고 있습니다. String 형식을 Double 형식으로 변환하는 법에 대해서도 알려주시면 감사하겠습니다.
위 2가지를 구현하고 싶은데 어떻게 하면 좋을지 고수님들의 도움이 필요합니다!
public class bt1_info extends Activity {
private static String url = "php 주소";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.bt1_info);
//줌인아웃 오버라이딩(덮어쓰기) 2줄
bt1_HttpHandler vv = new bt1_HttpHandler();
// Making a request to url and getting response
String jsonStr = vv.makeServiceCall(url);
Log.e(TAG, "Response from url: " + jsonStr);
if (jsonStr != null) {
try {
JSONObject jsonObj = new JSONObject(jsonStr);
// Getting JSON Array node
JSONArray contacts = jsonObj.getJSONArray("result");
// looping through All Contacts
for (int i = 0; i < contacts.length(); i++) {
JSONObject c = contacts.getJSONObject(i);
try {
String sp = c.getString("sp"); // 선별
String dp = c.getString("dp"); // 선별
} catch (Exception e) {
;
}
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
public class MainActivity extends AppCompatActivity implements TMapGpsManager.onLocationChangedCallback {
private Context mContext = null;
private boolean m_bTrackingMode = true;
private TMapGpsManager tmapgps = null;
private TMapView tmapview = null;
private static String mApiKey = "api app key 지정"; // 발급받은 appKey
private static int mMarkerID;
private ArrayList<TMapPoint> m_tmapPoint = new ArrayList<TMapPoint>();
private ArrayList<String> mArrayMarkerID = new ArrayList<String>();
private ArrayList<MapPoint> m_mapPoint = new ArrayList<MapPoint>();
@Override
public void onLocationChange(Location location) {
if (m_bTrackingMode) {
tmapview.setLocationPoint(location.getLongitude(), location.getLatitude());
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mContext = this;
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.mapview);
tmapview = new TMapView(this);
linearLayout.addView(tmapview);
tmapview.setSKPMapApiKey(mApiKey);
addPoint();
showMarkerPoint();
/* 현재 보는 방향 */
tmapview.setCompassMode(true);
/* 현위치 아이콘표시 */
tmapview.setIconVisibility(true);
tmapview.setZoomLevel(8);
/* 줌레벨 */
tmapview.setMapType(TMapView.MAPTYPE_STANDARD);
tmapview.setLanguage(TMapView.LANGUAGE_KOREAN);
tmapgps = new TMapGpsManager(MainActivity.this);
tmapgps.setMinTime(1000);
tmapgps.setMinDistance(5);
// tmapgps.setProvider(tmapgps.NETWORK_PROVIDER); //연결된 인터넷으로 현 위치를 받습니다. 실내일 때 유용합니다.
tmapgps.setProvider(tmapgps.GPS_PROVIDER); //gps로 현 위치를 잡습니다.
tmapgps.OpenGps();
/* 화면중심을 단말의 현재위치로 이동 */
tmapview.setTrackingMode(true);
tmapview.setSightVisible(true);
// 풍선에서 우측 버튼 클릭시 할 행동입니다
tmapview.setOnCalloutRightButtonClickListener(new TMapView.OnCalloutRightButtonClickCallback() {
@Override
public void onCalloutRightButton(TMapMarkerItem markerItem) {
Toast.makeText(MainActivity.this, "클릭", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(getApplicationContext(), cc.class);
startActivity(intent);
finish();
}
});
}
public void addPoint() { //여기에 핀을 꼽을 포인트들을 배열에 add해주세요!
m_mapPoint.add(new MapPoint("서울", 37.510350, 127.066847));
m_mapPoint.add(new MapPoint("강북", 35.841294, 128.565778));
m_mapPoint.add(new MapPoint("강서", 35.840804, 128.566922));
}