mapkitview not showing circle object overlay in Swift





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















My objective is to show a blue or yellow colored circle of a given radius so that later on I can search for cafes and pin them within that location.



I have this code so far and I have done everything I could! There is no error and the main location gets easily pinned and the annotation shows as well but just the circle doesn't appear.



//  ViewController2.swift

import UIKit
import MapKit

class ViewController2: UIViewController,MKMapViewDelegate,CLLocationManagerDelegate

{
@IBOutlet weak var mapView: MKMapView!
@IBAction func search(_ sender: Any)
{
//get location
var dec = location1.text
}

@IBOutlet weak var location1: UITextField!
@IBOutlet weak var label2: UILabel!
@IBOutlet weak var label11: UILabel!
@IBOutlet weak var baclbtn: UIButton!
@IBOutlet weak var map1: MKMapView!

var gllat:Double=0
var gllong:Double=0
var loc:String=""

override func viewDidLoad()
{ super.viewDidLoad()
map1.delegate=self

//pin location on required area
let anotaion = MKPointAnnotation()
anotaion.coordinate=CLLocationCoordinate2DMake(gllat, gllong)
self.mapView.addAnnotation(anotaion)

//zoom in to the required location
let coordinate:CLLocationCoordinate2D=CLLocationCoordinate2DMake(gllat,gllong)
let span1 = MKCoordinateSpan(latitudeDelta:0.1,longitudeDelta:0.1)
let region = MKCoordinateRegion(center:coordinate,span:span1)

self.mapView.setRegion(region, animated: true)

//add the circle object overlay
let _coordinate:CLLocationCoordinate2D=CLLocationCoordinate2DMake(gllat, gllong)
let radius1=CLLocationDistance(bitPattern: 1000)
let cl = MKCircle(center: _coordinate, radius: radius1)

self.mapView.addOverlay(cl)

}

func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer
{
guard let circelOverLay = overlay as? MKCircle else {return MKOverlayRenderer()}

let circleRenderer = MKCircleRenderer(circle: circelOverLay)
circleRenderer.fillColor = .blue
//circleRenderer.alpha = 0.2
return circleRenderer
}
}









share|improve this question

























  • Do you have two maps or just one map? Do you have the delegates setup for the mapView in storyboard? Don't see them in your code.

    – MwcsMac
    Nov 23 '18 at 18:59











  • i had one map but in 2ndviewcontroller.swift file but then i checked that it was mentioned everywhere to add the mapview as a delegate to the viewcontroller so i made a new map ie mapview and added the delegate etc but still nothing

    – Khattak Mahruna
    Nov 24 '18 at 7:41











  • what is the delegate setup ? dont we just add mkmapviewdelegate in the class header line ?

    – Khattak Mahruna
    Nov 24 '18 at 7:42











  • i solved this ! i just removed the line self.mapview.delegate=self as i had already dragged and made the mapview a delegate and also removed bitpattern for radius to exactly double ! it did the trick thanks

    – Khattak Mahruna
    Nov 24 '18 at 8:10











  • @KhattakMahruna if you solved this then you should put your solution as an answer and approve it so that others who are also stuck on this can benefit from it, too. Also, consider fixing the typo in your title ("overly" -> "overlay").

    – RX9
    Nov 26 '18 at 17:04


















0















My objective is to show a blue or yellow colored circle of a given radius so that later on I can search for cafes and pin them within that location.



I have this code so far and I have done everything I could! There is no error and the main location gets easily pinned and the annotation shows as well but just the circle doesn't appear.



//  ViewController2.swift

import UIKit
import MapKit

class ViewController2: UIViewController,MKMapViewDelegate,CLLocationManagerDelegate

{
@IBOutlet weak var mapView: MKMapView!
@IBAction func search(_ sender: Any)
{
//get location
var dec = location1.text
}

@IBOutlet weak var location1: UITextField!
@IBOutlet weak var label2: UILabel!
@IBOutlet weak var label11: UILabel!
@IBOutlet weak var baclbtn: UIButton!
@IBOutlet weak var map1: MKMapView!

var gllat:Double=0
var gllong:Double=0
var loc:String=""

override func viewDidLoad()
{ super.viewDidLoad()
map1.delegate=self

//pin location on required area
let anotaion = MKPointAnnotation()
anotaion.coordinate=CLLocationCoordinate2DMake(gllat, gllong)
self.mapView.addAnnotation(anotaion)

//zoom in to the required location
let coordinate:CLLocationCoordinate2D=CLLocationCoordinate2DMake(gllat,gllong)
let span1 = MKCoordinateSpan(latitudeDelta:0.1,longitudeDelta:0.1)
let region = MKCoordinateRegion(center:coordinate,span:span1)

self.mapView.setRegion(region, animated: true)

//add the circle object overlay
let _coordinate:CLLocationCoordinate2D=CLLocationCoordinate2DMake(gllat, gllong)
let radius1=CLLocationDistance(bitPattern: 1000)
let cl = MKCircle(center: _coordinate, radius: radius1)

self.mapView.addOverlay(cl)

}

func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer
{
guard let circelOverLay = overlay as? MKCircle else {return MKOverlayRenderer()}

let circleRenderer = MKCircleRenderer(circle: circelOverLay)
circleRenderer.fillColor = .blue
//circleRenderer.alpha = 0.2
return circleRenderer
}
}









share|improve this question

























  • Do you have two maps or just one map? Do you have the delegates setup for the mapView in storyboard? Don't see them in your code.

    – MwcsMac
    Nov 23 '18 at 18:59











  • i had one map but in 2ndviewcontroller.swift file but then i checked that it was mentioned everywhere to add the mapview as a delegate to the viewcontroller so i made a new map ie mapview and added the delegate etc but still nothing

    – Khattak Mahruna
    Nov 24 '18 at 7:41











  • what is the delegate setup ? dont we just add mkmapviewdelegate in the class header line ?

    – Khattak Mahruna
    Nov 24 '18 at 7:42











  • i solved this ! i just removed the line self.mapview.delegate=self as i had already dragged and made the mapview a delegate and also removed bitpattern for radius to exactly double ! it did the trick thanks

    – Khattak Mahruna
    Nov 24 '18 at 8:10











  • @KhattakMahruna if you solved this then you should put your solution as an answer and approve it so that others who are also stuck on this can benefit from it, too. Also, consider fixing the typo in your title ("overly" -> "overlay").

    – RX9
    Nov 26 '18 at 17:04














0












0








0








My objective is to show a blue or yellow colored circle of a given radius so that later on I can search for cafes and pin them within that location.



I have this code so far and I have done everything I could! There is no error and the main location gets easily pinned and the annotation shows as well but just the circle doesn't appear.



//  ViewController2.swift

import UIKit
import MapKit

class ViewController2: UIViewController,MKMapViewDelegate,CLLocationManagerDelegate

{
@IBOutlet weak var mapView: MKMapView!
@IBAction func search(_ sender: Any)
{
//get location
var dec = location1.text
}

@IBOutlet weak var location1: UITextField!
@IBOutlet weak var label2: UILabel!
@IBOutlet weak var label11: UILabel!
@IBOutlet weak var baclbtn: UIButton!
@IBOutlet weak var map1: MKMapView!

var gllat:Double=0
var gllong:Double=0
var loc:String=""

override func viewDidLoad()
{ super.viewDidLoad()
map1.delegate=self

//pin location on required area
let anotaion = MKPointAnnotation()
anotaion.coordinate=CLLocationCoordinate2DMake(gllat, gllong)
self.mapView.addAnnotation(anotaion)

//zoom in to the required location
let coordinate:CLLocationCoordinate2D=CLLocationCoordinate2DMake(gllat,gllong)
let span1 = MKCoordinateSpan(latitudeDelta:0.1,longitudeDelta:0.1)
let region = MKCoordinateRegion(center:coordinate,span:span1)

self.mapView.setRegion(region, animated: true)

//add the circle object overlay
let _coordinate:CLLocationCoordinate2D=CLLocationCoordinate2DMake(gllat, gllong)
let radius1=CLLocationDistance(bitPattern: 1000)
let cl = MKCircle(center: _coordinate, radius: radius1)

self.mapView.addOverlay(cl)

}

func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer
{
guard let circelOverLay = overlay as? MKCircle else {return MKOverlayRenderer()}

let circleRenderer = MKCircleRenderer(circle: circelOverLay)
circleRenderer.fillColor = .blue
//circleRenderer.alpha = 0.2
return circleRenderer
}
}









share|improve this question
















My objective is to show a blue or yellow colored circle of a given radius so that later on I can search for cafes and pin them within that location.



I have this code so far and I have done everything I could! There is no error and the main location gets easily pinned and the annotation shows as well but just the circle doesn't appear.



//  ViewController2.swift

import UIKit
import MapKit

class ViewController2: UIViewController,MKMapViewDelegate,CLLocationManagerDelegate

{
@IBOutlet weak var mapView: MKMapView!
@IBAction func search(_ sender: Any)
{
//get location
var dec = location1.text
}

@IBOutlet weak var location1: UITextField!
@IBOutlet weak var label2: UILabel!
@IBOutlet weak var label11: UILabel!
@IBOutlet weak var baclbtn: UIButton!
@IBOutlet weak var map1: MKMapView!

var gllat:Double=0
var gllong:Double=0
var loc:String=""

override func viewDidLoad()
{ super.viewDidLoad()
map1.delegate=self

//pin location on required area
let anotaion = MKPointAnnotation()
anotaion.coordinate=CLLocationCoordinate2DMake(gllat, gllong)
self.mapView.addAnnotation(anotaion)

//zoom in to the required location
let coordinate:CLLocationCoordinate2D=CLLocationCoordinate2DMake(gllat,gllong)
let span1 = MKCoordinateSpan(latitudeDelta:0.1,longitudeDelta:0.1)
let region = MKCoordinateRegion(center:coordinate,span:span1)

self.mapView.setRegion(region, animated: true)

//add the circle object overlay
let _coordinate:CLLocationCoordinate2D=CLLocationCoordinate2DMake(gllat, gllong)
let radius1=CLLocationDistance(bitPattern: 1000)
let cl = MKCircle(center: _coordinate, radius: radius1)

self.mapView.addOverlay(cl)

}

func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer
{
guard let circelOverLay = overlay as? MKCircle else {return MKOverlayRenderer()}

let circleRenderer = MKCircleRenderer(circle: circelOverLay)
circleRenderer.fillColor = .blue
//circleRenderer.alpha = 0.2
return circleRenderer
}
}






ios swift mapkit mapkitannotation






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 15 '18 at 11:19









Gerd Castan

3,25222161




3,25222161










asked Nov 23 '18 at 15:33









Khattak MahrunaKhattak Mahruna

12




12













  • Do you have two maps or just one map? Do you have the delegates setup for the mapView in storyboard? Don't see them in your code.

    – MwcsMac
    Nov 23 '18 at 18:59











  • i had one map but in 2ndviewcontroller.swift file but then i checked that it was mentioned everywhere to add the mapview as a delegate to the viewcontroller so i made a new map ie mapview and added the delegate etc but still nothing

    – Khattak Mahruna
    Nov 24 '18 at 7:41











  • what is the delegate setup ? dont we just add mkmapviewdelegate in the class header line ?

    – Khattak Mahruna
    Nov 24 '18 at 7:42











  • i solved this ! i just removed the line self.mapview.delegate=self as i had already dragged and made the mapview a delegate and also removed bitpattern for radius to exactly double ! it did the trick thanks

    – Khattak Mahruna
    Nov 24 '18 at 8:10











  • @KhattakMahruna if you solved this then you should put your solution as an answer and approve it so that others who are also stuck on this can benefit from it, too. Also, consider fixing the typo in your title ("overly" -> "overlay").

    – RX9
    Nov 26 '18 at 17:04



















  • Do you have two maps or just one map? Do you have the delegates setup for the mapView in storyboard? Don't see them in your code.

    – MwcsMac
    Nov 23 '18 at 18:59











  • i had one map but in 2ndviewcontroller.swift file but then i checked that it was mentioned everywhere to add the mapview as a delegate to the viewcontroller so i made a new map ie mapview and added the delegate etc but still nothing

    – Khattak Mahruna
    Nov 24 '18 at 7:41











  • what is the delegate setup ? dont we just add mkmapviewdelegate in the class header line ?

    – Khattak Mahruna
    Nov 24 '18 at 7:42











  • i solved this ! i just removed the line self.mapview.delegate=self as i had already dragged and made the mapview a delegate and also removed bitpattern for radius to exactly double ! it did the trick thanks

    – Khattak Mahruna
    Nov 24 '18 at 8:10











  • @KhattakMahruna if you solved this then you should put your solution as an answer and approve it so that others who are also stuck on this can benefit from it, too. Also, consider fixing the typo in your title ("overly" -> "overlay").

    – RX9
    Nov 26 '18 at 17:04

















Do you have two maps or just one map? Do you have the delegates setup for the mapView in storyboard? Don't see them in your code.

– MwcsMac
Nov 23 '18 at 18:59





Do you have two maps or just one map? Do you have the delegates setup for the mapView in storyboard? Don't see them in your code.

– MwcsMac
Nov 23 '18 at 18:59













i had one map but in 2ndviewcontroller.swift file but then i checked that it was mentioned everywhere to add the mapview as a delegate to the viewcontroller so i made a new map ie mapview and added the delegate etc but still nothing

– Khattak Mahruna
Nov 24 '18 at 7:41





i had one map but in 2ndviewcontroller.swift file but then i checked that it was mentioned everywhere to add the mapview as a delegate to the viewcontroller so i made a new map ie mapview and added the delegate etc but still nothing

– Khattak Mahruna
Nov 24 '18 at 7:41













what is the delegate setup ? dont we just add mkmapviewdelegate in the class header line ?

– Khattak Mahruna
Nov 24 '18 at 7:42





what is the delegate setup ? dont we just add mkmapviewdelegate in the class header line ?

– Khattak Mahruna
Nov 24 '18 at 7:42













i solved this ! i just removed the line self.mapview.delegate=self as i had already dragged and made the mapview a delegate and also removed bitpattern for radius to exactly double ! it did the trick thanks

– Khattak Mahruna
Nov 24 '18 at 8:10





i solved this ! i just removed the line self.mapview.delegate=self as i had already dragged and made the mapview a delegate and also removed bitpattern for radius to exactly double ! it did the trick thanks

– Khattak Mahruna
Nov 24 '18 at 8:10













@KhattakMahruna if you solved this then you should put your solution as an answer and approve it so that others who are also stuck on this can benefit from it, too. Also, consider fixing the typo in your title ("overly" -> "overlay").

– RX9
Nov 26 '18 at 17:04





@KhattakMahruna if you solved this then you should put your solution as an answer and approve it so that others who are also stuck on this can benefit from it, too. Also, consider fixing the typo in your title ("overly" -> "overlay").

– RX9
Nov 26 '18 at 17:04












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53449397%2fmapkitview-not-showing-circle-object-overlay-in-swift%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53449397%2fmapkitview-not-showing-circle-object-overlay-in-swift%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud

Zucchini