How to create bounder for GMSMarker
I have two GMSMarker
were one of the is moving and the other is not and I want to create something smilier to geofencing
where if the moving marker entered or left the bounder of the unmoving one I will able to do some actions,
I found an geofencing APIs by google but it is for android only, is there a way to do this in swift?
can the GMSCircle
be used to do so?
ios swift google-maps geofencing
add a comment |
I have two GMSMarker
were one of the is moving and the other is not and I want to create something smilier to geofencing
where if the moving marker entered or left the bounder of the unmoving one I will able to do some actions,
I found an geofencing APIs by google but it is for android only, is there a way to do this in swift?
can the GMSCircle
be used to do so?
ios swift google-maps geofencing
add a comment |
I have two GMSMarker
were one of the is moving and the other is not and I want to create something smilier to geofencing
where if the moving marker entered or left the bounder of the unmoving one I will able to do some actions,
I found an geofencing APIs by google but it is for android only, is there a way to do this in swift?
can the GMSCircle
be used to do so?
ios swift google-maps geofencing
I have two GMSMarker
were one of the is moving and the other is not and I want to create something smilier to geofencing
where if the moving marker entered or left the bounder of the unmoving one I will able to do some actions,
I found an geofencing APIs by google but it is for android only, is there a way to do this in swift?
can the GMSCircle
be used to do so?
ios swift google-maps geofencing
ios swift google-maps geofencing
edited Jan 1 at 7:39
Kaushik Makwana
854422
854422
asked Jan 1 at 6:41
NoufNouf
308215
308215
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Please check below code. Here is have created the area manually by setting the lat, long for each point. You can set your region by passing the lat,long in create area function and draw a circular region. Then make use of CLLocationManager delegate to monitor the marker.
var selectedPlace: GMSPlace?
let rect = GMSMutablePath()
func viewController(_ viewController: GMSAutocompleteViewController, didAutocompleteWith place: GMSPlace) {
print("Place name: (place.name)")
showPin(myPlace: place)
dismiss(animated: true, completion: nil)
}
func showPin(myPlace: GMSPlace){
mapView.clear()
createArea()
selectedPlace = myPlace
print((selectedPlace?.coordinate)!)
if(GMSGeometryContainsLocation((selectedPlace?.coordinate)!, rect, true))
{
print("YES: you are in this polygon.")
}else{
print("You do not appear to be in this polygon.")
}
func createArea(){
// Create a rectangular path
rect.add(CLLocationCoordinate2D(latitude: 18.882534, longitude: 72.801590))//Fort
rect.add(CLLocationCoordinate2D(latitude: 19.492122, longitude: 72.737045))//Virar
rect.add(CLLocationCoordinate2D(latitude: 19.476586, longitude: 73.096848))//Virar Right
rect.add(CLLocationCoordinate2D(latitude: 19.271893, longitude: 73.127060))//Kalyan
rect.add(CLLocationCoordinate2D(latitude: 19.186313, longitude: 73.243790))//Badlapur
//rect.add(CLLocationCoordinate2D(latitude: 18.811052, longitude: 73.547287))//Karjat
rect.add(CLLocationCoordinate2D(latitude: 18.966973, longitude: 73.107834))//Panvel
rect.add(CLLocationCoordinate2D(latitude: 19.021510, longitude: 72.975998))//Vashi
rect.add(CLLocationCoordinate2D(latitude: 18.882534, longitude: 72.801590))//Mumbai
// Create the polygon, and assign it to the map.
let polygon = GMSPolygon(path: rect)
polygon.fillColor = UIColor(red: 0.25, green: 0, blue: 0, alpha: 0.05);
polygon.strokeColor = .black
polygon.strokeWidth = 2
polygon.map = mapView
}
//CLLocationManager Delegates
func locationManager(_ manager: CLLocationManager, didStartMonitoringFor region: CLRegion){
print("Start Monitoring Region")
}
func locationManager(_ manager: CLLocationManager, didDetermineState state: CLRegionState, for region: CLRegion){
print("Determine Region State")
}
func locationManager(_ manager: CLLocationManager, didEnterRegion region: CLRegion){
print("Entered Monitoring Region")
}
func locationManager(_ manager: CLLocationManager, didExitRegion region: CLRegion){
print("Exited Monitoring Region")
}
func locationManager(_ manager: CLLocationManager, monitoringDidFailFor region: CLRegion?, withError error: Error){
print("Failed Monitoring Region")
}
if I use CLLocationManager I will tracking the user location right? if so , then that not want I want the user location in irrelevant in my case
– Nouf
Jan 3 at 7:08
If you are not using CLLocation manager.. you can use showPin function to draw your marker and check if marker is in the rect. You can draw rect using createArea() function.
– Yogesh Tandel
Jan 3 at 7:43
add a comment |
Have you tried CLRegion?
create one region at not moving marker with radius and call its delegate method for entering and exiting the moving marker.
and for CLLocationManger you can start monitoring for region.
same thing I am not use the CLLocationManger user location is irrelevant I have GMSmarker that I want to track
– Nouf
Jan 3 at 7:13
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53993519%2fhow-to-create-bounder-for-gmsmarker%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Please check below code. Here is have created the area manually by setting the lat, long for each point. You can set your region by passing the lat,long in create area function and draw a circular region. Then make use of CLLocationManager delegate to monitor the marker.
var selectedPlace: GMSPlace?
let rect = GMSMutablePath()
func viewController(_ viewController: GMSAutocompleteViewController, didAutocompleteWith place: GMSPlace) {
print("Place name: (place.name)")
showPin(myPlace: place)
dismiss(animated: true, completion: nil)
}
func showPin(myPlace: GMSPlace){
mapView.clear()
createArea()
selectedPlace = myPlace
print((selectedPlace?.coordinate)!)
if(GMSGeometryContainsLocation((selectedPlace?.coordinate)!, rect, true))
{
print("YES: you are in this polygon.")
}else{
print("You do not appear to be in this polygon.")
}
func createArea(){
// Create a rectangular path
rect.add(CLLocationCoordinate2D(latitude: 18.882534, longitude: 72.801590))//Fort
rect.add(CLLocationCoordinate2D(latitude: 19.492122, longitude: 72.737045))//Virar
rect.add(CLLocationCoordinate2D(latitude: 19.476586, longitude: 73.096848))//Virar Right
rect.add(CLLocationCoordinate2D(latitude: 19.271893, longitude: 73.127060))//Kalyan
rect.add(CLLocationCoordinate2D(latitude: 19.186313, longitude: 73.243790))//Badlapur
//rect.add(CLLocationCoordinate2D(latitude: 18.811052, longitude: 73.547287))//Karjat
rect.add(CLLocationCoordinate2D(latitude: 18.966973, longitude: 73.107834))//Panvel
rect.add(CLLocationCoordinate2D(latitude: 19.021510, longitude: 72.975998))//Vashi
rect.add(CLLocationCoordinate2D(latitude: 18.882534, longitude: 72.801590))//Mumbai
// Create the polygon, and assign it to the map.
let polygon = GMSPolygon(path: rect)
polygon.fillColor = UIColor(red: 0.25, green: 0, blue: 0, alpha: 0.05);
polygon.strokeColor = .black
polygon.strokeWidth = 2
polygon.map = mapView
}
//CLLocationManager Delegates
func locationManager(_ manager: CLLocationManager, didStartMonitoringFor region: CLRegion){
print("Start Monitoring Region")
}
func locationManager(_ manager: CLLocationManager, didDetermineState state: CLRegionState, for region: CLRegion){
print("Determine Region State")
}
func locationManager(_ manager: CLLocationManager, didEnterRegion region: CLRegion){
print("Entered Monitoring Region")
}
func locationManager(_ manager: CLLocationManager, didExitRegion region: CLRegion){
print("Exited Monitoring Region")
}
func locationManager(_ manager: CLLocationManager, monitoringDidFailFor region: CLRegion?, withError error: Error){
print("Failed Monitoring Region")
}
if I use CLLocationManager I will tracking the user location right? if so , then that not want I want the user location in irrelevant in my case
– Nouf
Jan 3 at 7:08
If you are not using CLLocation manager.. you can use showPin function to draw your marker and check if marker is in the rect. You can draw rect using createArea() function.
– Yogesh Tandel
Jan 3 at 7:43
add a comment |
Please check below code. Here is have created the area manually by setting the lat, long for each point. You can set your region by passing the lat,long in create area function and draw a circular region. Then make use of CLLocationManager delegate to monitor the marker.
var selectedPlace: GMSPlace?
let rect = GMSMutablePath()
func viewController(_ viewController: GMSAutocompleteViewController, didAutocompleteWith place: GMSPlace) {
print("Place name: (place.name)")
showPin(myPlace: place)
dismiss(animated: true, completion: nil)
}
func showPin(myPlace: GMSPlace){
mapView.clear()
createArea()
selectedPlace = myPlace
print((selectedPlace?.coordinate)!)
if(GMSGeometryContainsLocation((selectedPlace?.coordinate)!, rect, true))
{
print("YES: you are in this polygon.")
}else{
print("You do not appear to be in this polygon.")
}
func createArea(){
// Create a rectangular path
rect.add(CLLocationCoordinate2D(latitude: 18.882534, longitude: 72.801590))//Fort
rect.add(CLLocationCoordinate2D(latitude: 19.492122, longitude: 72.737045))//Virar
rect.add(CLLocationCoordinate2D(latitude: 19.476586, longitude: 73.096848))//Virar Right
rect.add(CLLocationCoordinate2D(latitude: 19.271893, longitude: 73.127060))//Kalyan
rect.add(CLLocationCoordinate2D(latitude: 19.186313, longitude: 73.243790))//Badlapur
//rect.add(CLLocationCoordinate2D(latitude: 18.811052, longitude: 73.547287))//Karjat
rect.add(CLLocationCoordinate2D(latitude: 18.966973, longitude: 73.107834))//Panvel
rect.add(CLLocationCoordinate2D(latitude: 19.021510, longitude: 72.975998))//Vashi
rect.add(CLLocationCoordinate2D(latitude: 18.882534, longitude: 72.801590))//Mumbai
// Create the polygon, and assign it to the map.
let polygon = GMSPolygon(path: rect)
polygon.fillColor = UIColor(red: 0.25, green: 0, blue: 0, alpha: 0.05);
polygon.strokeColor = .black
polygon.strokeWidth = 2
polygon.map = mapView
}
//CLLocationManager Delegates
func locationManager(_ manager: CLLocationManager, didStartMonitoringFor region: CLRegion){
print("Start Monitoring Region")
}
func locationManager(_ manager: CLLocationManager, didDetermineState state: CLRegionState, for region: CLRegion){
print("Determine Region State")
}
func locationManager(_ manager: CLLocationManager, didEnterRegion region: CLRegion){
print("Entered Monitoring Region")
}
func locationManager(_ manager: CLLocationManager, didExitRegion region: CLRegion){
print("Exited Monitoring Region")
}
func locationManager(_ manager: CLLocationManager, monitoringDidFailFor region: CLRegion?, withError error: Error){
print("Failed Monitoring Region")
}
if I use CLLocationManager I will tracking the user location right? if so , then that not want I want the user location in irrelevant in my case
– Nouf
Jan 3 at 7:08
If you are not using CLLocation manager.. you can use showPin function to draw your marker and check if marker is in the rect. You can draw rect using createArea() function.
– Yogesh Tandel
Jan 3 at 7:43
add a comment |
Please check below code. Here is have created the area manually by setting the lat, long for each point. You can set your region by passing the lat,long in create area function and draw a circular region. Then make use of CLLocationManager delegate to monitor the marker.
var selectedPlace: GMSPlace?
let rect = GMSMutablePath()
func viewController(_ viewController: GMSAutocompleteViewController, didAutocompleteWith place: GMSPlace) {
print("Place name: (place.name)")
showPin(myPlace: place)
dismiss(animated: true, completion: nil)
}
func showPin(myPlace: GMSPlace){
mapView.clear()
createArea()
selectedPlace = myPlace
print((selectedPlace?.coordinate)!)
if(GMSGeometryContainsLocation((selectedPlace?.coordinate)!, rect, true))
{
print("YES: you are in this polygon.")
}else{
print("You do not appear to be in this polygon.")
}
func createArea(){
// Create a rectangular path
rect.add(CLLocationCoordinate2D(latitude: 18.882534, longitude: 72.801590))//Fort
rect.add(CLLocationCoordinate2D(latitude: 19.492122, longitude: 72.737045))//Virar
rect.add(CLLocationCoordinate2D(latitude: 19.476586, longitude: 73.096848))//Virar Right
rect.add(CLLocationCoordinate2D(latitude: 19.271893, longitude: 73.127060))//Kalyan
rect.add(CLLocationCoordinate2D(latitude: 19.186313, longitude: 73.243790))//Badlapur
//rect.add(CLLocationCoordinate2D(latitude: 18.811052, longitude: 73.547287))//Karjat
rect.add(CLLocationCoordinate2D(latitude: 18.966973, longitude: 73.107834))//Panvel
rect.add(CLLocationCoordinate2D(latitude: 19.021510, longitude: 72.975998))//Vashi
rect.add(CLLocationCoordinate2D(latitude: 18.882534, longitude: 72.801590))//Mumbai
// Create the polygon, and assign it to the map.
let polygon = GMSPolygon(path: rect)
polygon.fillColor = UIColor(red: 0.25, green: 0, blue: 0, alpha: 0.05);
polygon.strokeColor = .black
polygon.strokeWidth = 2
polygon.map = mapView
}
//CLLocationManager Delegates
func locationManager(_ manager: CLLocationManager, didStartMonitoringFor region: CLRegion){
print("Start Monitoring Region")
}
func locationManager(_ manager: CLLocationManager, didDetermineState state: CLRegionState, for region: CLRegion){
print("Determine Region State")
}
func locationManager(_ manager: CLLocationManager, didEnterRegion region: CLRegion){
print("Entered Monitoring Region")
}
func locationManager(_ manager: CLLocationManager, didExitRegion region: CLRegion){
print("Exited Monitoring Region")
}
func locationManager(_ manager: CLLocationManager, monitoringDidFailFor region: CLRegion?, withError error: Error){
print("Failed Monitoring Region")
}
Please check below code. Here is have created the area manually by setting the lat, long for each point. You can set your region by passing the lat,long in create area function and draw a circular region. Then make use of CLLocationManager delegate to monitor the marker.
var selectedPlace: GMSPlace?
let rect = GMSMutablePath()
func viewController(_ viewController: GMSAutocompleteViewController, didAutocompleteWith place: GMSPlace) {
print("Place name: (place.name)")
showPin(myPlace: place)
dismiss(animated: true, completion: nil)
}
func showPin(myPlace: GMSPlace){
mapView.clear()
createArea()
selectedPlace = myPlace
print((selectedPlace?.coordinate)!)
if(GMSGeometryContainsLocation((selectedPlace?.coordinate)!, rect, true))
{
print("YES: you are in this polygon.")
}else{
print("You do not appear to be in this polygon.")
}
func createArea(){
// Create a rectangular path
rect.add(CLLocationCoordinate2D(latitude: 18.882534, longitude: 72.801590))//Fort
rect.add(CLLocationCoordinate2D(latitude: 19.492122, longitude: 72.737045))//Virar
rect.add(CLLocationCoordinate2D(latitude: 19.476586, longitude: 73.096848))//Virar Right
rect.add(CLLocationCoordinate2D(latitude: 19.271893, longitude: 73.127060))//Kalyan
rect.add(CLLocationCoordinate2D(latitude: 19.186313, longitude: 73.243790))//Badlapur
//rect.add(CLLocationCoordinate2D(latitude: 18.811052, longitude: 73.547287))//Karjat
rect.add(CLLocationCoordinate2D(latitude: 18.966973, longitude: 73.107834))//Panvel
rect.add(CLLocationCoordinate2D(latitude: 19.021510, longitude: 72.975998))//Vashi
rect.add(CLLocationCoordinate2D(latitude: 18.882534, longitude: 72.801590))//Mumbai
// Create the polygon, and assign it to the map.
let polygon = GMSPolygon(path: rect)
polygon.fillColor = UIColor(red: 0.25, green: 0, blue: 0, alpha: 0.05);
polygon.strokeColor = .black
polygon.strokeWidth = 2
polygon.map = mapView
}
//CLLocationManager Delegates
func locationManager(_ manager: CLLocationManager, didStartMonitoringFor region: CLRegion){
print("Start Monitoring Region")
}
func locationManager(_ manager: CLLocationManager, didDetermineState state: CLRegionState, for region: CLRegion){
print("Determine Region State")
}
func locationManager(_ manager: CLLocationManager, didEnterRegion region: CLRegion){
print("Entered Monitoring Region")
}
func locationManager(_ manager: CLLocationManager, didExitRegion region: CLRegion){
print("Exited Monitoring Region")
}
func locationManager(_ manager: CLLocationManager, monitoringDidFailFor region: CLRegion?, withError error: Error){
print("Failed Monitoring Region")
}
answered Jan 2 at 5:02


Yogesh TandelYogesh Tandel
7781812
7781812
if I use CLLocationManager I will tracking the user location right? if so , then that not want I want the user location in irrelevant in my case
– Nouf
Jan 3 at 7:08
If you are not using CLLocation manager.. you can use showPin function to draw your marker and check if marker is in the rect. You can draw rect using createArea() function.
– Yogesh Tandel
Jan 3 at 7:43
add a comment |
if I use CLLocationManager I will tracking the user location right? if so , then that not want I want the user location in irrelevant in my case
– Nouf
Jan 3 at 7:08
If you are not using CLLocation manager.. you can use showPin function to draw your marker and check if marker is in the rect. You can draw rect using createArea() function.
– Yogesh Tandel
Jan 3 at 7:43
if I use CLLocationManager I will tracking the user location right? if so , then that not want I want the user location in irrelevant in my case
– Nouf
Jan 3 at 7:08
if I use CLLocationManager I will tracking the user location right? if so , then that not want I want the user location in irrelevant in my case
– Nouf
Jan 3 at 7:08
If you are not using CLLocation manager.. you can use showPin function to draw your marker and check if marker is in the rect. You can draw rect using createArea() function.
– Yogesh Tandel
Jan 3 at 7:43
If you are not using CLLocation manager.. you can use showPin function to draw your marker and check if marker is in the rect. You can draw rect using createArea() function.
– Yogesh Tandel
Jan 3 at 7:43
add a comment |
Have you tried CLRegion?
create one region at not moving marker with radius and call its delegate method for entering and exiting the moving marker.
and for CLLocationManger you can start monitoring for region.
same thing I am not use the CLLocationManger user location is irrelevant I have GMSmarker that I want to track
– Nouf
Jan 3 at 7:13
add a comment |
Have you tried CLRegion?
create one region at not moving marker with radius and call its delegate method for entering and exiting the moving marker.
and for CLLocationManger you can start monitoring for region.
same thing I am not use the CLLocationManger user location is irrelevant I have GMSmarker that I want to track
– Nouf
Jan 3 at 7:13
add a comment |
Have you tried CLRegion?
create one region at not moving marker with radius and call its delegate method for entering and exiting the moving marker.
and for CLLocationManger you can start monitoring for region.
Have you tried CLRegion?
create one region at not moving marker with radius and call its delegate method for entering and exiting the moving marker.
and for CLLocationManger you can start monitoring for region.
answered Jan 1 at 10:44


Akash SonejiAkash Soneji
28111
28111
same thing I am not use the CLLocationManger user location is irrelevant I have GMSmarker that I want to track
– Nouf
Jan 3 at 7:13
add a comment |
same thing I am not use the CLLocationManger user location is irrelevant I have GMSmarker that I want to track
– Nouf
Jan 3 at 7:13
same thing I am not use the CLLocationManger user location is irrelevant I have GMSmarker that I want to track
– Nouf
Jan 3 at 7:13
same thing I am not use the CLLocationManger user location is irrelevant I have GMSmarker that I want to track
– Nouf
Jan 3 at 7:13
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53993519%2fhow-to-create-bounder-for-gmsmarker%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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