Google maps creation of geofencing for iOS - google-maps

Does google maps provide the ability to create geofence in iOS?
Similar to this for Android:
http://developer.android.com/training/location/geofencing.html
Thank you.

Just in case someone else end up here :
https://www.raywenderlich.com/136165/core-location-geofencing-tutorial
Geofencing notifies your app when its device enters or leaves geographical regions you set up. It lets you make cools that can trigger a notification whenever you leave home, or greet users with the latest and greatest deals whenever favorite shops are nearby. In this geofencing tutorial, you’ll learn how to use region monitoring in iOS with Swift – using the Region Monitoring API in Core Location.[...]

In swift 5 You can create the geofencing by using the Google Map Object. In the view did load or anywhere in the code where you want to initialize the path just instantiate the GMSMutablePath object
var path : GMSMutablePath!
//In viewdidload
path = GMSMutablePath()
let lat = Double(i.latitude ?? "0") ?? 0.0
let lng = Double(i.longitude ?? "0") ?? 0.0
print(lat,lng)
path.add(CLLocationCoordinate2D(latitude: lat, longitude: lng))
let polyline = GMSPolyline(path: path)
polyline.strokeColor = AppColor.authFontColor
polyline.strokeWidth = 3.0
polyline.map = googleMapView

Related

How to extract route GPX from a Google Maps route?

My objective is to extract a route which some user would have created on Google Maps into a GPX file containing latitude longitudes for further use in other apps.
The route will be shared via a link like this - https://goo.gl/maps/HcikiDXFwN2coeFN8
Interestingly, this app is already doing what I want to do - https://mapstogpx.com/ and https://www.gpsvisualizer.com/convert_input?convert_format=gpx. I just want to know how they are doing it so that I can emulate it for my own needs.
Since both the tools I've mentioned also require providing a Google Maps API key with the directions API enabled, my initial guess is that these tools first parse the webpage for the waypoints and then use those waypoints in a Directions API call to get all the route trackpoints.
Thanks
The solution lies in the "data" param in the expanded url for the google maps route link.
Lets take this URL for example - https://goo.gl/maps/zrcP5gL1cd2AHGoq8
This expands to https://www.google.com/maps/dir/Eiffel+Tower,+Paris,+France/Palais+Garnier,+Pl.+de+l'Op%C3%A9ra,+75009+Paris,+France/#48.8606129,2.2961092,14z/am=t/data=!4m29!4m28!1m20!1m1!1s0x47e6701f7e8337b5:0xa2cb58dd28914524!2m2!1d2.2930458!2d48.8560934!3m4!1m2!1d2.3122286!2d48.8490916!3s0x47e6702fa62d0bc5:0xd2d94ed604f2e5a0!3m4!1m2!1d2.3035972!2d48.8729816!3s0x47e66fc1755cf609:0x3c5040f902b41a5f!3m4!1m2!1d2.3235117!2d48.8581242!3s0x47e66e2ac3bca3ed:0x1c289763e3096e61!1m5!1m1!1s0x47e66e30d4668339:0xa9abf21c286d0767!2m2!1d2.3316014!2d48.8719697!3e0
On closer examination, you will see that the data param has lat-lng coordinates embedded in it. For example this
!1d2.2930458!2d48.8560934 or !1d2.3122286!2d48.8490916. These are longitude latitude pairs representing various waypoints on the route. The longitude always starts with !1d and ends with !2d and the latitude starts with !2d and ends with !3.
Here is a small kotlin method to extract all the coordinates :
//https://stackoverflow.com/a/62191093/3090120
fun String?.indexesOf(pat: String, ignoreCase: Boolean = true): List<Int> =
pat.toRegex(if (ignoreCase) setOf(RegexOption.IGNORE_CASE) else emptySet())
.findAll(this ?: "")
.map { it.range.first }
.toList()
fun extractCoordinates(expandedUrl: String): List<LatLng> {
val latLngList = arrayListOf<LatLng>()
val indexes = expandedUrl.indexesOf("!1d")
indexes.forEach {
val coordinatesStr = expandedUrl.substring(it + 3).substringBefore("!3").split("!2d")
latLngList.add(LatLng(coordinatesStr[1].toDouble(), coordinatesStr[0].toDouble()))
}
return latLngList
}
The result with this string would be
[lat/lng: (48.8560934,2.2930458), lat/lng: (48.8490916,2.3122286), lat/lng: (48.8729816,2.3035972), lat/lng: (48.8581242,2.3235117), lat/lng: (48.8719697,2.3316014)]
Once we have all the lat-lng pairs we can simply fire off a Google Maps Directions API call and recreate the route in the link and export it as a GPX file.

Google maps destination SwiftUI

I am working on a project where users can add the addresses of their clients. I managed to make these addresses to be interactive so that when you tap on them a sheet shows the option to open either GoogleMaps or Apple Maps. However I am not sure how to set the specific address I tap to be the destination when the map opens. This is what I have:
.actionSheet(isPresented: $showingSheet){
let latitude = 51.49
let longitude = -30
let appleURL = "http://maps.apple.com/?daddr=\(latitude),\(longitude)"
let googleURL = "comgooglemaps://?daddr=\(latitude),\(longitude)&directionsmode=driving"
//let wazeURL = "waze://?ll=\(latitude),\(longitude)&navigate=false"
let googleItem = ("Google Map", URL(string:googleURL)!)
//let wazeItem = ("Waze", URL(string:wazeURL)!)
var installedNavigationApps = [("Apple Maps", URL(string:appleURL)!)]
if UIApplication.shared.canOpenURL(googleItem.1) {
installedNavigationApps.append(googleItem)
}
// if UIApplication.shared.canOpenURL(wazeItem.1) {
// installedNavigationApps.append(wazeItem)
// }
var buttons: [ActionSheet.Button] = []
for app in installedNavigationApps {
let button: ActionSheet.Button = .default(Text(app.0)) {
UIApplication.shared.open(app.1, options: [:], completionHandler: nil)
}
buttons.append(button)
}
let cancel: ActionSheet.Button = .cancel()
buttons.append(cancel)
return ActionSheet(title: Text("Navigate"), message: Text("Select an app..."), buttons: buttons)
Any suggestions?
Both Apple Maps and Google Maps have a similar URL scheme for opening their map for driving directions.
Apple Maps reference: https://developer.apple.com/library/archive/featuredarticles/iPhoneURLScheme_Reference/MapLinks/MapLinks.html
Google Maps URL scheme for iOS: https://developers.google.com/maps/documentation/urls/ios-urlscheme#directions
In both cases, the daddr value you're passing can be sent a full address, which the Maps product will then geocode and pinpoint.
You're currently sending a stringified version of your lat/lng coordinates in that string, which each maps product can use to derive a location. But there neither scheme seems to support an option of "here are the coordinates I want to use, and this is the address I want to show" – it's one or the other.
So if you take the address you have and enter it as a single string (don't forget to URL encode it – you may find it easiest to assemble your URL using the URLComponents and URLQueryItem helper objects) you ought to be able to use that encoded string as a new daddr value.

Flickr API image unavailable windows phone

I'm trying to use flicke's api to import images into a Windows Phone app and display them on the phones panoramic dispaly.
I'm new to flickr's API and am stuck ATM.
I've tried the following call:
// original string flickString = "https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=cc9babb2754c1d29837bea480c97013e&text=game+of+thrones&format=json&nojsoncallback=1&api_sig=bb86a60e9e42f31950bf53d25fc45f08";
string flickString = "https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=cc9babb2754c1d29837bea480c97013e&text=game+of+thrones&extras=url_sq%2C+url_t%2C+url_s%2C+url_q%2C+url_m%2C+url_n%2C+url_z%2C+url_c%2C+url_l%2C+url_o+&format=json&nojsoncallback=1&api_sig=9e74e094d8c6a7496fc66e070f5c0898";
var baseUrl = string.Format(flickString, flickrAPIKey);
string flickrResult = await client.GetStringAsync(baseUrl);
FlickrData flickrApiData = JsonConvert.DeserializeObject<FlickrData>(flickrResult);
if(flickrApiData.stat == "ok")
{
foreach (Photo data in flickrApiData.photos.photo)
{
// To retrieve one photo
// http://farm{farmid}.staticflickr.com/{server-id}/{id}_{secret}{size}.jpeg
//string photoUrl = "http://farm{0}.staticflickr.com/{1}/{2}_{3}_o.jpeg";
//string photoUrl = "http://farm{0}.staticflickr.com/{1}/{2}_{3}_b.jpeg";
//string photoUrl = "http://farm{0}.staticflickr.com/{1}/{2}_{3}_n.jpg";
string photoUrl = "http://farm{0}.staticflickr.com/{1}/{2}_{3}"
string baseFlickrUrl = string.Format(photoUrl,
data.farm,
data.server,
data.id,
data.secret);
flickr1Image.Source = new BitmapImage(new Uri(baseFlickrUrl));
break;
}
}
}
When I deploy and run the app I get an image saying that this image is unavailiablemessage every time? I've tried changing the search terms etc and still get the sme message. Which is making me wondor if I've missed something setting up my account with flickr earlier that I'm not aware of? It's very frustrating - help please.
Thanks to card_master for his help so far
I'm also integrating with Flickr. I'm creating a web site that uses their api.
I'm using FlickrNet. This is an open source .net library that you can use to call the Flickr Services. This is a C# library.
The benefit of using it on a mobile application you can take advantage of the caching. It allows you to store images in the phones storage. This won't work on a web application though.

Map route not working in Titanium Appcelerator

i'm having some trouble with Maps Route y Maps V2 on Android. So the problem is when i put a route, like this:
var cord1= {
latitude:29.078685,
longitude:-110.971205,
};
var cord2= {
latitude:29.081496,
longitude:-110.959232,
};
var route1 = [cord1, cord2];
var route = MapModule.createRoute({
points : route1,
color : "red",
width : 5.0
});
$.mapview.addRoute(route);
And yeah, now i have a map route in my map, but the route is straight, totally straight
Picture of the map route!
The route is not using the streets, is just a straight line, not sable at all, can you help me?
My specifications:
Mac OS Maverick
Module: Ti.map (API V2)
Titanium SDK 3.2.2.GA
Titanium Studio, build: 3.2.1.201402041146
(c) Copyright 2012-2013 by Appcelerator, Inc. All rights reserved.
Build: jenkins-titanium-rcp-master-95 (origin/master)
Date: 04 February 2014, 11:47:38
You need more coordinates not just a start an end but many points in between. Since this is just one route, your coordinates must be stored in an array consecutively. That array should be used for the points property when creating a route. Here's an example from appecelerator's documents and the route examples are at the very bottom of the page: http://docs.appcelerator.com/titanium/3.0/#!/guide/Native_Maps_and_Annotations
Like this:
var _points = []; // The array used to contain the points in a route
//Your coordinates
var cord1= {
latitude:29.078685,
longitude:-110.971205,
};
_points.push(cord1);
var cord2= {
latitude:29.081496,
longitude:-110.959232,
};
_points.push(cord2);
// Create your route
var route = MapModule.createRoute({
points : _points,
color : "#f00",
width : 5.0
});
// Add route to map!
$.mapview.addRoute(route);
In titanium if you provide only two points in route then it will draw a straight line between those points. If you want to make more accurate route, then try to provide more [cords] points.
try KitchenSink
I too was stuck with the same problem But find a solution to this . The solution is using a Google Places API that provides you points between your starting and destination points as a result a more accurate route is drawn on the map!!!!Hope this works for you .

Working with Google maps on Windows store

Google Maps on windows phone
How can I add pushpins and get directions in here.
Do I require to use JavaScript
Note in this method:
function addMarkers () {
    for (var i = 0; i < dataResults.features.length; i++) {
        var quake = dataResults.features[i];
        var coors = quake.geometry.coordinates;
        var latLong = new google.maps.LatLng(coors[1], coors[0]);
        var marker = new google.maps.Marker({
            position: latLong,
            map: map
            //icon: getCircle(earthquake.properties.mag)
        });
    }
}
The important part in that is when we create a marker we give it a map object, which was initialized from the div 'mapdisplay' so we initialize that map object here
function initialize() {
map = new google.maps.Map(document.getElementById('mapdisplay'), {
zoom: 3,
...
and in turn it is passed as the 'map' parameter in the call to:
new google.maps.Marker
This is using the returned earthquake data from the USGS and simply creating the new marker.
You can simply use a similar technique to add your own pins (ie markers), and yes - you need JavaScript : )
https://developers.google.com/maps/documentation/javascript/overlays
In order to get directions see "Displaying the DirectionsResult" at https://developers.google.com/maps/documentation/javascript/directions
or an overview at
https://developers.google.com/maps/documentation/directions/
For a working sample (it's not win8 but it shouldn't matter as I'm assuming you are using a Windows 8 HTML/JS application)
Get directions in new window Google maps API v3
Now with that said - you can also use Bing Maps as well and it's quite documented for Windows 8 applications
Bing Maps for Windows Store Apps
Bing Maps SDK for Windows Store apps Samples