如何在 Android Studio (Google MAP API)中使用微调器绘制折线?这就是它的工作原理,每当用户单击微调器中的按钮时,它将在Google地图中绘制折线。这是我们需要的最后一件事,请帮助我们。我找不到使用时间微调器绘制线条的答案。
package com.example.admin.mobiletrafficanalyzer2;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import java.util.ArrayList;
import java.util.List;
public class challmanila extends FragmentActivity implements OnMapReadyCallback {
Spinner spinner;
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_challmanila);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
spinner=(Spinner)findViewById(R.id.spinner);
List<String> list=new ArrayList<String>();
list.add("12:00AM - 1:00AM");
list.add("1:01AM - 2:00AM");
list.add("2:01AM - 3:30AM");
list.add("3:31AM - 4:30AM");
list.add("4:31AM - 5:30AM");
list.add("5:31AM - 6:00AM");
list.add("6:01AM - 6:15AM");
list.add("6:16AM - 10:00AM");
list.add("10:01AM - 12:00PM");
list.add("12:01PM - 2:30PM");
list.add("2:31PM - 6:00PM");
list.add("6:01PM - 9PM");
list.add("9:01PM - 10:30PM");
list.add("10:31PM - 12:59PM");
ArrayAdapter<String> arrayAdapter=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list);
arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(arrayAdapter);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int i, long l) {
spinner.setSelection(i);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney and move the camera
LatLng challmanila = new LatLng(14.589892, 120.981580);
mMap.addMarker(new MarkerOptions().position(challmanila).title("Marker in City Hall Manila"));
float zoomLevel = 16.0f;
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(challmanila, zoomLevel=16.0f));
}
}
答案 0 :(得分:0)
只要在微调器上选择了项目,仅添加折线到地图怎么样?
+----+----+----+----+
|col1|col2|col3|col4|
+----+----+----+----+
| A| 100|jose| 1|
| B| 70|jose| 1|
| C| 50|jose| 1|
| A| 100| li| 2|
| B| 70| li| 2|
| C| 50| li| 2|
| A| 100| liz| 3|
| B| 70| liz| 3|
| C| 50| liz| 3|
+----+----+----+----+
对于mMap = null的情况,您可能会编写一些代码,这意味着尚未加载地图或错误。因此,在这种情况下,您希望将polylineOptions存储在某个位置,并在地图准备就绪时显示它。