1

i write a map viewer and i want to get Latitude and Longitude from user, then show him the location. i use menu for this work. but i don't know how show him something to enter the values. this is my code.

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

    MapView view = (MapView) findViewById(R.id.themap);
    view.setBuiltInZoomControls(true);

    final MapController control = view.getController();

    LocationManager manager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    LocationListener listener = new LocationListener() {

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onProviderEnabled(String provider) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onProviderDisabled(String provider) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onLocationChanged(Location location) {
            control.setCenter(new GeoPoint((int)location.getLatitude(), (int)location.getLongitude()));
        }
    };
    manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, listener);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    return super.onOptionsItemSelected(item);
}

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

}

so i have 2 questions. first how can i create a menu for my locations. i must use context menu or something else. second, if i get locations, i can enter them directly to my Latitude and Longitude? in my code i use the default location of user.

Hosein
  • 475
  • 2
  • 7
  • 21

3 Answers3

0

Well if I am understanding you correctly you can do this 2 ways.

1) In your xml layout add an input box and button then on click set your location.

2) Override your onTouch and have and alert box pop up and ask for the long and lat. Then set it accordingly.

Both these will be setting your overLay: http://developer.android.com/resources/tutorials/views/hello-mapview.html

one of many overlay tutorials: http://eagle.phys.utk.edu/guidry/android/mapOverlayDemo.html

Rick
  • 1,153
  • 1
  • 18
  • 37
0

If u only want to show your current position yo can use MyLoicationOverlay class:

miPunto = new MyLocationOverlay(this, eMapa);
            eMapa.getOverlays().add(miPunto);
            miPunto.enableCompass();
            miPunto.enableMyLocation();

If you wont to use this, yo must to get your location and then use an itemizedoverlay

colymore
  • 11,776
  • 13
  • 48
  • 90
0

This is my code, It works fine with me

 Drawable marker=getResources().getDrawable(R.drawable.mapmarker);  
    marker.setBounds( (int) (-marker.getIntrinsicWidth()/2),  
                            -marker.getIntrinsicHeight(), 
                            (int) (marker.getIntrinsicWidth()/2),  
                            0); 

    InterestingLocations funPlaces = 
                  new InterestingLocations(marker); 

Add your overlay Item in here.

    mapView.getOverlays().add(funPlaces); 

class InterestingLocations extends ItemizedOverlay { 
    private ArrayList<OverlayItem> locations = 
            new ArrayList<OverlayItem>(); 
    private GeoPoint center = null; 

    public InterestingLocations(Drawable marker) 
    { 
        super(marker); 

        // Put your custom Lat, Long in here , 
        GeoPoint disneySevenLagoon = 
            new GeoPoint((int)(28.410067*1000000), 
                         (int)(-81.583699*1000000));

        locations.add(new OverlayItem(disneySevenLagoon ,  
                      "Seven Seas Lagoon", "Seven Seas Lagoon")); 
        populate(); 
    } 
Tai Tran
  • 1,406
  • 3
  • 15
  • 27