我创建了一个由listview和map组成的应用程序。当用户从列表视图中选择时,地图将自动转到该位置。此外,位置的配置文件将显示。按钮组成的按钮,当用户点击时,它将指示等待并获得经度的纬度。我不知道我的代码有什么问题,因为它无法获得位置的纬度和经度。我认为我的问题是在字符串网址中我无法获得经度和经度,但我不知道正确的代码来获取它。
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
LatLng latLngtofocus = new LatLng(Double.parseDouble(GetLocation.get(i).getlatitude()), Double.parseDouble(GetLocation.get(i).getlatitude()));
map.animateCamera(CameraUpdateFactory.newLatLngZoom(latlngtofocus, 17.0f));
}
LocationListView = findViewById(R.id.locationlayout);
ViewGroup parent = (ViewGroup) LocationListView.getParent();
parent.removeView(LocationListView);
// inflate your profile view (or get the reference to it if it's already inflated)
LocationProfileView = getLayoutInflater().inflate(R.layout.profile_location, parent, false);
// add it to the parent
parent.addView(LocationProfileView);
btnwaze = (Button) findViewById(R.id.waze);
btnwaze.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try
{
String url = "waze://?q=(Double.parseDouble(GetLocation.get(i).getlatitude()), Double.parseDouble(GetLocation.get(i).getlongitude()))";
Intent intent = new Intent( Intent.ACTION_VIEW, Uri.parse( url ) );
startActivity( intent );
}
catch ( ActivityNotFoundException ex )
{
Intent intent =
new Intent( Intent.ACTION_VIEW, Uri.parse( "market://details?id=com.waze" ) );
startActivity(intent);
}
}
});
});
答案 0 :(得分:1)
设置为final int i并将之前的代码更改为String url =“waze://?ll =”+ GetLocation.get(i).getlatitude()+“,”+ GetLocation.get(i).getlongitude( )+ “&安培;导航= YES”;