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"
;
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();
String jsonStr = vv.makeServiceCall(url);
Log.e(TAG,
"Response from url: "
+ jsonStr);
if
(jsonStr !=
null
) {
try
{
JSONObject jsonObj =
new
JSONObject(jsonStr);
JSONArray contacts = jsonObj.getJSONArray(
"result"
);
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.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() {
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
;
item1.setTMapPoint(point);
item1.setName(m_mapPoint.get(i).getName());
item1.setVisible(item1.VISIBLE);
item1.setCalloutTitle(m_mapPoint.get(i).getName());
item1.setCanShowCallout(
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);
}
}
}