A
A
Airat19952014-11-03 14:47:33
Android
Airat1995, 2014-11-03 14:47:33

How to put markers on google maps?

Hello, I just can’t put markers on the map, I received the key, the map is loading, but there are no signs on it, maybe I’m doing something wrong?
Used code:

private MapFragment _myMapFragment;
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.MapLayout);
            string[] data = TakeDataFromPreference.TakeData(this);
            var locator = new Geolocator(this) {DesiredAccuracy = 50};
            LatLng home = new LatLng(Convert.ToSingle(data[4]), Convert.ToSingle(data[5]));
            GoogleMapOptions mapOptions = new GoogleMapOptions()
                .InvokeMapType(GoogleMap.MapTypeNormal)
                .InvokeZoomControlsEnabled(false)
                .InvokeCompassEnabled(true);
            _myMapFragment = MapFragment.NewInstance(mapOptions);
            FragmentTransaction tx = FragmentManager.BeginTransaction();
            tx.Add(Resource.Id.container, _myMapFragment);
            tx.Commit();
            GoogleMap map = _myMapFragment.Map;

            MarkerOptions marker1 = new MarkerOptions();
            if (map == null)
            {
                map = _myMapFragment.Map;
                if (map != null)
                {
                    marker1.SetPosition(home);
                    marker1.SetTitle("Home sweet home");
                    marker1.Visible(true);
                    marker1.Draggable(true);
                    map.AddMarker(marker1);
                }
            }
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Intentio, 2014-11-03
@Intentio

Good day. Here is a simple code example that sets up a group of markers. Pay attention to the number of parameters when setting the marker:

cursor = db.getPlaces(intent.getLongExtra("PriceListID",0));
        if (cursor.moveToFirst()){
            do{
                addMarker(
                       cursor.getString(cursor.getColumnIndex("Name")),
                       cursor.getString(cursor.getColumnIndex("Address")),
                       cursor.getDouble(cursor.getColumnIndex("GPSlat")),
                       cursor.getDouble(cursor.getColumnIndex("GPSlon"))
                );
                Log.d(LOG_TAG, "Marker added");

            }
            while (cursor.moveToNext());
        }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question