Adding a Circle with Google Maps API

JoshuaDJoshuaD USMember
edited January 2014 in Xamarin.Android

I'm attempting to create a method where I can pass a LatLng parameter so I can add circles over top of multiple areas on a map. Below is a test method of what I'm going for. I have reviewed the Xamarin and Google documentation for the Shapes overlays, but I am unable to get this code to actually display the Circle shape on the map. Currently I do not have a parameter passing into the method while I'm testing with it. Same story goes for the radius. I'm certainly going to scale it down once it is working...
private void AddCircleToMap() { CircleOptions circleOptions = new CircleOptions (); circleOptions.InvokeCenter(new LatLng (0, 0)); circleOptions.InvokeRadius(5000); circleOptions.InvokeFillColor(Android.Graphics.Color.Blue); Circle newCircle = _map.AddCircle(circleOptions); newCircle.Visible = true; }

I'm calling the method after the other test markers have been created within the SetupMapIfNeeded() method. The end result currently is that the other markers from the example code will display as they always have, but my new method to insert a test Circle will not.
//INITIAL DECLARATIONS private GoogleMap _map; private MapFragment _mapFragment;
private void SetupMapIfNeeded() { if (_map == null) { _map = _mapFragment.Map; if (_map != null) { AddMonkeyMarkersToMap(); AddInitialPolarBarToMap(); AddCircleToMap(); } } }

Suggestions? Comments? I'd certainly appreciate any direction on it.

Answers

  • JoshuaDJoshuaD USMember

    Success!
    I believe my problem was that I had the createCircle method calling on the initial load, before the _map had time to actually have any data populated within it (thus there was a null exception error).

    I don't suppose I can mark my own reply and make this topic answered? Mods, feel free to lock up or close this topic if you find it necessary.

Sign In or Register to comment.