This is my firebase data using Split method i try to separate lat/lan
value stored in Firebase, but only first value show but second value cannot get.error occured and stop run.String lat=gpsVal[0] can assign but String lang=gpsVal1 cannot assign.app close.
but when i add manual value lat/lng: (7.714195099999999,81.6947587)" to example variable then can assign both value(String lat=gpsVal[0],lang=gpsVal1) to variable
This my code:
final ArrayList <String> locationnew = new ArrayList <String>();
database.orderByChild("ItemName").equalTo(name).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot){
for(DataSnapshot suggestionSnapshot : dataSnapshot.getChildren())
{
itcat=suggestionSnapshot.getKey();
String loc=suggestionSnapshot.child("ShopLocation").getValue().toString();
names1.add(itcat);
locationnew.add(loc);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
// Toast.makeText(getApplicationContext(), "AWW SNAP... Something is Wrong.", Toast.LENGTH_LONG).show();
}
});
String[] loca=new String[1000];
for(int i=0; i < locationnew.size(); i++)
{
loca[i]=locationnew.get(i);
}
String find_lat_lan = "";
serch2.setText(String.valueOf(loca[0]));
String example = serch2.getText().toString();
Matcher m = Pattern.compile("\\(([^)]+)\\)").matcher(example);
while(m.find()) {
find_lat_lan = m.group(1) ;
}
String[] gpsVal = find_lat_lan.split(",");
String lat=gpsVal[0];
String lang=gpsVal[1];