안녕하세요.
티맵 네비 연동 구현 중 데이터베이스 정보를 가져와 티맵의 자ㄹ표를 지정해주고 싶습니다.
데이터베이스 불러오는 부분을 하고 있는데 자꾸만 서버와 연결이 되지 않는다 합니다.
어떤 부분이 문제인지 궁금합니다.
아래는 소스입니다.
public class MainActivity extends Activity implements TMapGpsManager.onLocationChangedCallback {
private String TAG = MainActivity.class.getSimpleName();
private Context mContext = null;
private boolean m_bTrackingMode = true;
private TMapGpsManager tmapgps = null;
private TMapView tmapview = null;
private static String mApiKey = "mApiKey"; // 발급받은 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>();
private static String url = ".php";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
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);
String Name = c.getString("Name");
TextView Linet = (TextView) findViewById(R.id.line);
Linet.setText(Name);
}
} catch (final JSONException e) {
Log.e(TAG, "Json parsing error: " + e.getMessage());
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(),
"Json parsing error: " + e.getMessage(),
Toast.LENGTH_LONG)
.show();
}
});
}
} else {
Log.e(TAG, "Couldn't get json from server.");
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(),
"Couldn't get json from server. Check LogCat for possible errors!",
Toast.LENGTH_LONG)
.show();
}
});
}
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) {
int v = m_mapPoint.size();
Toast.makeText(MainActivity.this, "클릭", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(getApplicationContext(), cc.class);
intent.putExtra("check4", m_mapPoint.get(1).getName());
startActivity(intent);
finish();
}
});
}
@Override
public void onLocationChange(Location location) {
if (m_bTrackingMode) {
tmapview.setLocationPoint(location.getLongitude(), location.getLatitude());
}
}
public void addPoint() { //여기에 핀을 꼽을 포인트들을 배열에 add해주세요!
// 강남 //
// m_mapPoint.add(new MapPoint("서울교량", 37.510350, 127.066847));
for (double i = 0; i < 10; i+=0.1) {
m_mapPoint.add(new MapPoint("강북교량", 35.841294 + i, 128.565778));
m_mapPoint.add(new MapPoint("강서교량", 35.840804 + i, 128.566922 + i));
}
}
public void showMarkerPoint() {// 마커 찍는거 빨간색 포인트.
for (int i = 0; i < m_mapPoint.size(); i++) {
TMapPoint point = new TMapPoint(m_mapPoint.get(i).getLatitude(), m_mapPoint.get(i).getLongitude());
TMapMarkerItem item1 = new TMapMarkerItem();
Bitmap bitmap = null;
// bitmap = BitmapFactory.decodeResource(mContext.getResources(), R.mipmap.vv0);
//poi_dot은 지도에 꼽을 빨간 핀 이미지입니다
item1.setTMapPoint(point);
item1.setName(m_mapPoint.get(i).getName());
item1.setVisible(item1.VISIBLE);
// item1.setIcon(bitmap);
// bitmap = BitmapFactory.decodeResource(mContext.getResources(), R.mipmap.ic_launcher);
// 풍선뷰 안의 항목에 글을 지정합니다.
item1.setCalloutTitle(m_mapPoint.get(i).getName());
// item1.setCalloutSubTitle("");
item1.setCanShowCallout(true);
// item1.setAutoCalloutVisible(true);
Bitmap bitmap_i = BitmapFactory.decodeResource(mContext.getResources(), R.mipmap.ic_launcher);
item1.setCalloutRightButtonImage(bitmap_i);
String strID = String.format("pmarker%d", mMarkerID++);
tmapview.addMarkerItem(strID, item1);
mArrayMarkerID.add(strID);
}
}
}