0

This is my situation: I have an Activity which reads the current Location, shows the Address in a TextView and sets a Marker on a "small" GoogleMap" at the bottom area of the Activity. At this map ScrollGestures are disabled - it's just to show the current location to the user.

IF the currect Location is not correct the User should be able to click somewhere on the map, which opens a new activity where he can drag the marker to his correct position.

My question is: How can i start a new Activity by clicking somewhere on the map.

I tried this, but i was not able to put an Intent in the onClick method: a link!

Here is my code:

    private void initilizeMap() {
    if (googleMap == null) {
        googleMap = ((MapFragment) getFragmentManager().findFragmentById(
                R.id.map)).getMap();
        //googleMap.setMyLocationEnabled(true);

        googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(
                lat, lng), 13));
        googleMap.getUiSettings().setScrollGesturesEnabled(false);
        googleMap.setOnMapClickListener(new OnMapClickListener() {

            @Override
            public void onMapClick(LatLng arg0) {

                Intent intent2 = new Intent(this, SettingsActivity.class);
                startActivity(intent2);
            }
        });
        addMarker();

        }
    }
}
Community
  • 1
  • 1
JuergenKie
  • 109
  • 1
  • 10
  • What you mean by "but i was not able to put an Intent in the onClick method" ? – amit singh Feb 19 '14 at 16:59
  • eclipse gave me an error (it didnt find the intent class because its no available in an innerclass of an activity).i think nasageek solved my problem. i'll try that tomorrow. – JuergenKie Feb 19 '14 at 23:16

1 Answers1

1

When you use this in your call to startActivity, you are not referencing a Context as you should be. Instead, you are referencing the instance of the anonymous inner class you have created for the onMapClickListener. You either need to replace this with YourActivityName.this or with YourFragmentName.this.getActivity() depending on what the outer class is (seems like it's a Fragment...)

Please more clear about what error you are receiving next time.

NasaGeek
  • 2,138
  • 1
  • 15
  • 19