私は自分のNavドロワの断片の中にGoogleマップを持っていて、それをアクティビティに切り替えたくありません。Google Mapsに線が描画されていません
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);
しかし、これら二つの点の間に線を追加されていない。しかし、単に地図上に線を描画するために、私は、次のコードビットを追加しました。私はこのSOの質問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年代の前にサインをつけるとは思わなかった。 –