//내 현재 위치 가져오기(10초마다 갱신)
private void requestMyLocation() {
locationmanager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
try {
long minTime = 10000;
float minDistance = 1;
locationmanager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
minTime,
minDistance,
new LocationListener() {
@Override
public void onLocationChanged(Location location) {
try {
showCurrentLocation(location);
} catch (JSONException e) {
e.printStackTrace();
}
try {
addPictures(location);
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onProviderDisabled(String provider) {
Intent i = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(i);
}
}
);
Location lastLocation = locationmanager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (lastLocation != null) {
showCurrentLocation(lastLocation);
}
locationmanager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER,
10000,
1,
new LocationListener() {
@Override
public void onLocationChanged(Location location) {
try {
showCurrentLocation(location);
} catch (JSONException e) {
e.printStackTrace();
}
try {
addPictures(location);
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onProviderDisabled(String provider) {
}
}
);
} catch (SecurityException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
}
//내 현재 위치 띄우기
private void showCurrentLocation(Location location) throws JSONException {
LatLng curPoint = new LatLng(location.getLatitude(), location.getLongitude());
map.animateCamera(CameraUpdateFactory.newLatLngZoom(curPoint, 15));
showMyLocationMarker(location);
addPictures(location);
}
private void showMyLocationMarker(Location location) {
if (myLocationMarker == null) {
myLocationMarker = new MarkerOptions();
myLocationMarker.position(new LatLng(location.getLatitude(), location.getLongitude()));
myLocationMarker.title("내위치");
myLocationMarker.snippet("내위치");
myLocationMarker.icon(BitmapDescriptorFactory.fromResource(R.mipmap.dial));
map.addMarker(myLocationMarker);
} else {
myLocationMarker.position(new LatLng(location.getLatitude(), location.getLongitude()));
}
latitude = location.getLatitude();
longitude = location.getLongitude();
}
private void addPictures(final Location location) throws JSONException {
int pictureResId = R.mipmap.ic_start;
JSONObject jsonObject = new JSONObject(mJsonString);
JSONArray jsonArray = jsonObject.getJSONArray(TAG_JSON);
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject item = jsonArray.getJSONObject(i);
String schedule_id = "3";
String id = "ys";
String name = "yeseul";
//상대방 위치 띄우는 코드
for(int j = 0; j <= 1; j++)
{
friendMarker[j] = new MarkerOptions();
friendMarker[j].icon(BitmapDescriptorFactory.fromResource(pictureResId));
friendMarker[j].position(new LatLng(Double.valueOf(longitude1[j]), Double.valueOf(latitude1[j])));
friendMarker[j].icon(BitmapDescriptorFactory.fromResource(pictureResId));
map.addMarker(friendMarker[j]);
}
내 위치를 서버에서 받아서 지도에 띄우는 것 까지는 했는데
서버에 저장한 위도 경도를 받아서 상대방 위치를 띄우려 하는데
이부분에서 해결이 잘 안됩니다......
이것만 완성하면 되는데 해결이 안되어서 며칠째 힘드네요
도와주십쇼 고수님들...