내 탐색 서랍 조각 중 하나에 Google지도가 있고 활동으로 전환하고 싶지 않습니다.Google지도에 선이 그려지지 않습니다.
lineOptions = new PolylineOptions()
.add(new LatLng(33.927085040000001, -118.39129683))
.add(new LatLng(33.927085969382027, -118.39129820011991))
.add(new LatLng(33.927081024586677, -118.39130352185116))
.add(new LatLng(33.927077084498386, -118.39130986277655))
.add(new LatLng(33.92707405365519, -118.39131496827862))
.add(new LatLng(33.927066722586623, -118.39131750469446))
.add(new LatLng(33.927068689880947, -118.39131823397425))
.add(new LatLng(33.927068030419839, -118.39131796208994))
.add(new LatLng(33.927065982966624, -118.39132090766913))
.add(new LatLng(33.927065258415212, -118.3913193654964))
.width(5)
.color(Color.RED);
line = mMap.addPolyline(lineOptions);
그러나, 그 두 점 사이의 줄을 추가되지 않습니다 그러나 단순히지도에 선을 그릴 수, 나는 다음과 같은 코드를 추가했습니다. 나는이 질문에서 그 코드를 가지고있다. Drawing a line/path on Google Maps 그리고 그 사람은 그것이 효과가 있다고 말했다. 그래서 내가 어디로 잘못 가고 있는지 확실하지 않습니다. 내가 하드 코드 값을 가지고있는 이유는이 점을 파악한 후에 JSON 응답에서 여러 경로를 플로팅 할 것이기 때문입니다. 여기에 모든 코드입니다 : 나는 목록을 추가 할 생각
public class ThirdFragment extends Fragment implements OnMapReadyCallback {
View myView;
private GoogleMap mMap;
MapFragment mapFrag;
private Polyline line;
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
myView = inflater.inflate(R.layout.third_layout, container, false);
return myView;
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mapFrag = (MapFragment) getChildFragmentManager().findFragmentById(R.id.map);
mapFrag.getMapAsync(this);
//mapFrag.onResume();
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
line = mMap.addPolyline(new PolylineOptions()
.add(new LatLng(33.8031, 118.0726), new LatLng(33.9192, 118.4165))
.width(5)
.color(Color.RED));
mMap.setMyLocationEnabled(true);
Criteria criteria = new Criteria();
LocationManager locationManager = (LocationManager)getActivity().getSystemService(Context.LOCATION_SERVICE);
String provider = locationManager.getBestProvider(criteria, false);
Location location = locationManager.getLastKnownLocation(provider);
double lat = location.getLatitude();
double lng = location.getLongitude();
LatLng coordinate = new LatLng(lat, lng);
CameraUpdate yourLocation = CameraUpdateFactory.newLatLngZoom(coordinate, 13);
mMap.animateCamera(yourLocation);
} else {
final AlertDialog alertDialogGPS = new AlertDialog.Builder(getActivity()).create();
alertDialogGPS.setTitle("Info");
alertDialogGPS.setMessage("Looks like you have not given GPS permissions. Please give GPS permissions and return back to the app.");
alertDialogGPS.setIcon(android.R.drawable.ic_dialog_alert);
alertDialogGPS.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent intentSettings = new Intent(Settings.ACTION_APPLICATION_SETTINGS);
startActivity(intentSettings);
alertDialogGPS.dismiss();
}
});
alertDialogGPS.show();
}
}
@Override
public void onResume() {
super.onResume();
if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
mapFrag.getMapAsync(this);
}
else {
}
}
}
코드가 괜찮은 것 같습니다. 어쩌면 카메라가 확대되어 선을 볼 수 없습니까? 세계관을 축소하면 선을 볼 수 없습니까? 더군다나 코드가 호출되는지 확인해야합니까 (디버그 모드)? –
축소해도 여전히 보이지 않습니다. 게다가 라인은 현재 위치에서 시작됩니다. 'line = mMap.addPolyline' 이후의 모든 것이 호출되기 때문에 코드를 호출해야합니다. –
나는 바보 같은 느낌, 나는 봤어 좌표와 118의 앞에 - 기호를 넣어 생각하지 않았다. –