【发布时间】:2019-06-30 14:41:45
【问题描述】:
如何使用 Android Studio(Google MAP API)中的微调器绘制折线?这就是它的工作原理,每当用户单击微调器中的按钮时,它都会在谷歌地图中绘制折线。这是我们需要的最后一件事,请帮助我们。我找不到使用时间微调器绘制线条的答案。
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));
}
}
【问题讨论】:
标签: java google-maps android-studio