public void pointLocation(){
if(gmap!=null){
gmap.setOnMapLongClickListener(new OnMapLongClickListener() {
@Override
public void onMapLongClick(LatLng latlng) {
// TODO Auto-generated method stub
double lat = latlng.latitude;
double lng = latlng.longitude;
mVisible=gmap.addMarker(new MarkerOptions().position(new LatLng(lat, lng)));
Toast.makeText(getApplicationContext(), "Latitude :"+" "+lat+"Longitude :"+" "+lng, Toast.LENGTH_LONG).show();
}
});
mVisible.setVisible(false);//marker setVisible off so that old marker get destroy and new get appear
}
}
Asked
Active
Viewed 138 times
-1

Anonymous
- 11,748
- 6
- 35
- 57

user2273146
- 1,602
- 2
- 14
- 27
-
What do u want to do exactly ?? – Terril Thomas Mar 29 '14 at 10:14
-
ahh i want to add marker whenever user touch on screen and i did that but if user keep on touching screen multiple marker get appear but i want to make appear only one marker whenever user touch on screen..So can you please help me and if u didn't understand again then let me know – user2273146 Mar 29 '14 at 10:17
-
add a boolean set it true for the first instance and then false eksewgere – Terril Thomas Mar 29 '14 at 10:19
-
can u help me with the code please i was trying the same thing but not working.. – user2273146 Mar 29 '14 at 10:23
-
share the class on pastebin – Terril Thomas Mar 29 '14 at 10:25
-
sorry i didnt get u.. should i need to paste my code in that site..if yes then this is a link http://pastebin.com/xgBFrabw where i paste it – user2273146 Mar 29 '14 at 10:30
1 Answers
1
package com.sample;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Window;
import android.widget.Toast;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMapLongClickListener;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import com.sample.R;
public class MainActivity extends FragmentActivity {
GoogleMap gmap;
// GPSTracker gpsTracker;
SupportMapFragment mapFragment;
Marker mVisible;
boolean checkCall = true;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.selectlocation);
// gpsTracker = new GPSTracker(this);
mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.maplocation);
userPosition();
pointLocation();
}
public void userPosition() {
gmap = mapFragment.getMap();
if (gmap != null) {
// if (gpsTracker.canGetLocation()) {
// double latCurrentloc = gpsTracker.getLatitude();
// double lngCurrentloc = gpsTracker.getLongitude();
LatLng pointer = new LatLng(17.2145632, 8.2345876);
gmap.addMarker(new MarkerOptions().position(pointer).title(
"Hello world"));
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(pointer).zoom(12).build();
gmap.animateCamera(CameraUpdateFactory
.newCameraPosition(cameraPosition));
// }
}
}
public void pointLocation() {
if (gmap != null) {
// mVisible.setVisible(true);
gmap.setOnMapLongClickListener(new OnMapLongClickListener() {
@Override
public void onMapLongClick(LatLng latlng) {
if (checkCall) {
double lat = latlng.latitude;
double lng = latlng.longitude;
mVisible = gmap.addMarker(new MarkerOptions()
.position(new LatLng(lat, lng)));
Toast.makeText(
getApplicationContext(),
"Latitude :" + " " + lat + "Longitude :" + " "
+ lng, Toast.LENGTH_LONG).show();
checkCall = false;
}
}
});
}
}
}

Terril Thomas
- 1,486
- 13
- 32
-
Well i have done the same changes that you have mention above but now the problem is only one time the marker get created and if i need to change again marker the code does not let me to touch and create a new marker in screen..<
– user2273146 Mar 30 '14 at 07:03 -
-
-
This how I solve my problem any way tnx being part of the process.. public void pointLocation(){ gmap.setOnMapLongClickListener(new OnMapLongClickListener() { @Override public void onMapLongClick(LatLng latlng) { // TODO Auto-generated method stub if(marker!=null){ marker.remove(); } double lat = latlng.latitude; double lng = latlng.longitude; marker=gmap.addMarker(new MarkerOptions().position(new LatLng(lat, lng))); Toast.makeText(getApplicationContext(), "Latitude :"+" "+lat+"Longitude :"+" "+lng, Toast.LENGTH_LONG).show(); } }); } } – user2273146 Mar 31 '14 at 01:25