tylerpachal

Populating map with many points during onCreate()

Discussion created by tylerpachal on Nov 10, 2013
I am trying to adapt the Geocode sample app for my purposes.

The Geocode sample app has a text box where the user enters an address, and the address is then displayed on the map as a blue circle.  There is a button who's onClick() called the locate() function, which then calls the addess2Pnt() function.  This is from the sample and is all working fine.

/*
 * Submit address for geocoding
 */
public void locate(View view) {
 // remove any previous graphics
 //locationLayer.removeAll();
  
 // obtain address from text box
 EditText addr = (EditText)findViewById(R.id.editText1);
  
 //Get the address from the textbox
 String address = addr.getText().toString();
  
 // send address to conversion method
 address2Pnt(address);
}

/*
 * Convert input address into geocoded point
 */
private void address2Pnt(String address) {
 try 
 {
  // create Locator parameters from single line address string
  LocatorFindParameters findParams = new LocatorFindParameters(address);
   
  // set the search country to Canada
  findParams.setSourceCountry("Canada");
   
  // limit the results to 2
  findParams.setMaxLocations(2);
   
  // set address spatial reference to match map
  findParams.setOutSR(mMapView.getSpatialReference());
   
  // execute async task to geocode address
  new Geocoder().execute(findParams);
 } 
  
 catch (Exception e) 
 {
  e.printStackTrace();
 }
}


During the MapActivity's onCreate(), I would like to draw a bunch of points on the map (in the end I will be getting rid of the text box), which come from an ArrayList of addresses.  Unfortunately this isn't working, even though the strings in the ArrayList work fine when I enter them into the text field manually.  When I try to add the value from the list, it always draws it below Africa (the 0,0 point of the map).


ArrayList<String> stops = new ArrayList<String>();
stops.add("6311 Coburg Road, Halifax, Nova Scotia, Canada");
  
for (String s : stops)
{
 address2Pnt(s);
}



Does anyone know why this isn't working?

Outcomes