How to add the coding for displaying the address when a particular set of latitude and longitude is

Posted by KKC on Stack Overflow See other posts from Stack Overflow or by KKC
Published on 2010-04-28T02:40:14Z Indexed on 2010/04/28 2:53 UTC
Read the original article Hit count: 377

Filed under:
|
|

import com.google.android.maps.GeoPoint; import com.google.android.maps.MapActivity; import com.google.android.maps.MapController; import com.google.android.maps.MapView;

import android.os.Bundle; import android.view.KeyEvent; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Spinner; import android.widget.AdapterView.OnItemSelectedListener;

public class PopularAttractions extends MapActivity {

private String[ ][ ] locations = {
        {"Singapore Zoological Garden","1.40502,103.793449"},
        {"Singapore Night Safari","1.4037,103.789467"},
        {"Jurong BirdPark","1.32005,103.707153"},
        {"Jurong Reptile Park","1.321177,103.708486"},
        {"Singapore Botanic Garden","1.31471,103.815689"},
        {"Sungei Buloh Wetland Reserver","1.445144,103.729595"},
        {"Escape Theme Park","1.38104,103.936928"},
        {"Snow City","1.32823,103.74263"},
        {"Super Ice World","1.300422,103.875348"},
        {"Chinatown Heritage Center","1.2836,103.84425"},
        {"Singapore Science Center","1.3249,103.740578"},
        {"Red Dot Design Museum","1.277762,103.846225"},
        {"G-Max Reverse Bungy","1.2906,103.845322"},
        {"NEWater Visitor Center","1.33105,103.955311"}

};

private Spinner spinnerView;
private MapView mapView;
private MapController mc;




/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);


    spinnerView = (Spinner) this.findViewById(R.id.spinner1);
    mapView = (MapView) findViewById(R.id.mapview1);
    mc = mapView.getController();

    ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(this, android.R.layout.simple_spinner_dropdown_item);

    //--add the various locations---
    for(int i = 0; i < locations.length; i++)
        adapter.add(locations[i][0]);

    adapter.setDropDownViewResource(
            android.R.layout.simple_spinner_dropdown_item);
    spinnerView.setAdapter(adapter);
    spinnerView.setOnItemSelectedListener(selectListener);

    gotoSelected();
}

//---when user selects an item---
private OnItemSelectedListener selectListener = new OnItemSelectedListener() {

    //---these are two methods you need to implement---

    public void onItemSelected(
            AdapterView<?>parent, View v, int position, long id)
    {
        gotoSelected();
    }


    public void onNothingSelected(AdapterView<?> arg0) {}

};

//---when an item has been selected---
public void gotoSelected()
{
    int index = spinnerView.getSelectedItemPosition();
    String[] coordinates = locations[index][1].split(",");
    double lat = Double.parseDouble(coordinates[0]);
    double lng = Double.parseDouble(coordinates[1]);

    GeoPoint location = new GeoPoint (
            (int)(lat * 1E6),
            (int)(lng * 1E6));

    mc.animateTo(location);
    mc.setZoom(16);


    if (mapView.isSatellite())
    mapView.setSatellite(false);

    else
        mapView.setStreetView(true);

    mapView.invalidate();

}




public boolean onKeyDown(int keyCode, KeyEvent event) 
{
    MapController mc = mapView.getController(); 
    switch (keyCode) 
    {
        case KeyEvent.KEYCODE_3:
            mc.zoomIn();
            break;
        case KeyEvent.KEYCODE_1:
            mc.zoomOut();
            break;
    }
    return super.onKeyDown(keyCode, event);
}    

@Override
protected boolean isRouteDisplayed(){
    //TODO Auto-generated method sub
    return false; 

}

}

© Stack Overflow or respective owner

Related posts about java

Related posts about android