Android 在谷歌地图中回收要标记的视图数据
SearchAdapterAndroid 在谷歌地图中回收要标记的视图数据,android,google-maps,android-intent,android-recyclerview,Android,Google Maps,Android Intent,Android Recyclerview,SearchAdapter public class SearchAdapter extends RecyclerView.Adapter<SearchAdapter.SearchViewHolder> { Context context; ArrayList<String> studentNameList; ArrayList<String> studentMatrikList; ArrayList<String>
public class SearchAdapter extends RecyclerView.Adapter<SearchAdapter.SearchViewHolder> {
Context context;
ArrayList<String> studentNameList;
ArrayList<String> studentMatrikList;
ArrayList<String> studentPhoneList;
ArrayList<String> studentAddressList;
ArrayList<String> studentLatList;
ArrayList<String> studentLngList;
class SearchViewHolder extends RecyclerView.ViewHolder{
TextView studentName, studentMatrik, studentPhone, studentAddress, studentLat, studentLng;
CheckBox checkBox;
Button buttonMap;
public SearchViewHolder(View itemView) {
super(itemView);
studentName = (TextView) itemView.findViewById(R.id.studentName);
studentMatrik = (TextView) itemView.findViewById(R.id.studentMatrik);
studentPhone = (TextView) itemView.findViewById(R.id.studentPhone);
studentAddress = (TextView) itemView.findViewById(R.id.studentAddress);
studentLat = (TextView) itemView.findViewById(R.id.studentLat);
studentLng = (TextView) itemView.findViewById(R.id.studentLng);
checkBox = (CheckBox) itemView.findViewById(R.id.checkBox);
buttonMap = (Button) itemView.findViewById(R.id.buttonMap);
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
if (isChecked) {
Toast.makeText(SearchAdapter.this.context,
"Selected student is " + studentName.getText(),Toast.LENGTH_LONG).show();
} else {
}
}
});
}
}
public SearchAdapter(Context context, ArrayList<String> studentNameList, ArrayList<String> studentMatrikList, ArrayList<String> studentPhoneList, ArrayList<String> studentAddressList, ArrayList<String> studentMailList, ArrayList<String> studentConList) {
this.context = context;
this.studentNameList = studentNameList;
this.studentMatrikList = studentMatrikList;
this.studentPhoneList = studentPhoneList;
this.studentAddressList = studentAddressList;
this.studentMailList = studentMailList;
this.studentConList = studentConList;
}
@Override
public SearchAdapter.SearchViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.list_layout, parent, false);
return new SearchAdapter.SearchViewHolder(view);
}
@Override
public void onBindViewHolder(SearchViewHolder holder, int position) {
holder.studentName.setText(studentNameList.get(position));
holder.studentMatrik.setText(studentMatrikList.get(position));
holder.studentPhone.setText(studentPhoneList.get(position));
holder.studentAddress.setText(studentAddressList.get(position));
holder.studentLat.setText(studentMailList.get(position));
holder.studentLng.setText(studentConList.get(position));
holder.buttonMap.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
Intent intent = new Intent(context, MapsActivity.class);
context.startActivity(intent);
}
});
}
@Override
public int getItemCount() {
return studentNameList.size();
}
}
文本视图纬度值:
studentLat = (TextView) itemView.findViewById(R.id.studentLat);
文本视图经度值
studentLng = (TextView) itemView.findViewById(R.id.studentLng);
@Override
public void onBindViewHolder(SearchViewHolder holder, int position) {
holder.studentName.setText(studentNameList.get(position));
holder.studentMatrik.setText(studentMatrikList.get(position));
holder.studentPhone.setText(studentPhoneList.get(position));
holder.studentAddress.setText(studentAddressList.get(position));
holder.studentLat.setText(studentMailList.get(position));
holder.studentLng.setText(studentConList.get(position));
holder.buttonMap.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
Intent intent = new Intent(context, MapsActivity.class);
context.startActivity(intent);
}
});
}
是否可以基于textview地址或纬度和经度在Google地图中链接按钮映射和显示标记?我以前问过这个问题,但找不到解决办法
holder.buttonMap.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
Intent intent = new Intent(context, MapsActivity.class);
intent.putExtra("address",holder.studentAddress..getText().toString();)
context.startActivity(intent);
}
});
MapsActivity.class
内部Oncreate()
如果您想在谷歌地图上显示您的地址,请使用以下简单方法
Intent searchAddress = new Intent(Intent.ACTION_VIEW,Uri.parse("geo:0,0?q="+address));
startActivity(searchAddress);
(或)
使用下面的方法从地址中获取lat和lng,然后在谷歌地图中添加标记…如果您未获取lat lng值,则表示您的地址无效
public GeoPoint getLocationFromAddress(String searchAddress){
Geocoder coder = new Geocoder(this);
List<Address> address;
GeoPoint p1 = null;
try {
address = coder.getFromLocationName(searchAddress,5);
if (address==null) {
return null;
}
Address location=address.get(0);
location.getLatitude();
location.getLongitude();
p1 = new GeoPoint((double) (location.getLatitude() * 1E6),
(double) (location.getLongitude() * 1E6));
return p1;
}
}
你的意思是,当我点击recylerview按钮时,你想在Google地图上显示标记吗right@GowthamanM是的,标记将基于文本视图address@JavaGuy我希望这可能会帮助你…如果你有任何pbm让我知道…有用的不要忘了向银行回复。。。我尝试intent.putExtra(“address”,holder.studentAddress..getText().toString();),但得到的错误是,变量holder是从内部访问的class@JavaGuy获取(位置)就像这样通过..make是位置作为最后的int post
Intent searchAddress = new Intent(Intent.ACTION_VIEW,Uri.parse("geo:0,0?q="+address));
startActivity(searchAddress);
public GeoPoint getLocationFromAddress(String searchAddress){
Geocoder coder = new Geocoder(this);
List<Address> address;
GeoPoint p1 = null;
try {
address = coder.getFromLocationName(searchAddress,5);
if (address==null) {
return null;
}
Address location=address.get(0);
location.getLatitude();
location.getLongitude();
p1 = new GeoPoint((double) (location.getLatitude() * 1E6),
(double) (location.getLongitude() * 1E6));
return p1;
}
}
if (latitude != null && longitude != null)
{
mGoogleMap2.addMarker(new MarkerOptions()
.position(new LatLng(latitude, longitude)));
mGoogleMap2.moveCamera(CameraUpdateFactory.newLatLngZoom(
new LatLng(latitude, longitude), 10));
}