-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FMD-183 fix geo URI for different platforms
- Loading branch information
Showing
3 changed files
with
95 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,85 @@ | ||
using System; | ||
using GeoClient.Models; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
using System.Web; | ||
using GeoClient.Models; | ||
using Xamarin.Forms; | ||
|
||
namespace GeoClient.Views.Utils | ||
{ | ||
public class GeoPointUtil | ||
{ | ||
public static Uri CreateGeoUri(GeoPoint geoPoint, string geoPointerTag) | ||
public static bool NotBlank(string inputString) | ||
{ | ||
return inputString != null && inputString.Trim() != ""; | ||
} | ||
|
||
public static List<Uri> CreateUrisForGeoPoint(GeoPoint geoPoint, string geoPointerTag) | ||
{ | ||
Uri geoUri = null; | ||
List<Uri> uriList = null; | ||
|
||
if (GeoPointUtil.IsGeoPointValid(geoPoint)) | ||
{ | ||
var request = string.Format( | ||
"geo:{0},{1}?q={0},{1}({2})", | ||
geoPoint.Latitude.ToString(CultureInfo.InvariantCulture), | ||
geoPoint.Longitude.ToString(CultureInfo.InvariantCulture), | ||
HttpUtility.UrlEncode(geoPointerTag)); | ||
geoUri = new Uri(request); | ||
uriList = new List<Uri>(); | ||
string latitudeString = geoPoint.Latitude.ToString(CultureInfo.InvariantCulture); | ||
string longitudeString = geoPoint.Longitude.ToString(CultureInfo.InvariantCulture); | ||
|
||
uriList.Add(CreateGeoUri(latitudeString, longitudeString, geoPointerTag)); | ||
if (IsRunningOnIOS()) | ||
{ | ||
uriList.Add(CreateAppleMapsUri(latitudeString, longitudeString, geoPointerTag)); | ||
uriList.Add(CreateGoogleMapsUri(latitudeString, longitudeString)); | ||
} else | ||
{ | ||
uriList.Add(CreateGoogleMapsUri(latitudeString, longitudeString)); | ||
uriList.Add(CreateAppleMapsUri(latitudeString, longitudeString, geoPointerTag)); | ||
} | ||
} | ||
else | ||
{ | ||
Console.WriteLine("Cannot create geo URI for geo point: " + geoPoint); | ||
} | ||
|
||
return geoUri; | ||
return uriList; | ||
} | ||
|
||
private static bool IsGeoPointValid(GeoPoint geoPoint) | ||
private static Uri CreateGeoUri(string latitudeString, string longitudeString, string geoPointerTag) | ||
{ | ||
return geoPoint != null; | ||
var uriString = string.Format( | ||
"geo:{0},{1}?q={0},{1}({2})", | ||
latitudeString, | ||
longitudeString, | ||
HttpUtility.UrlEncode(geoPointerTag)); | ||
return new Uri(uriString); | ||
} | ||
|
||
public static bool NotBlank(string inputString) | ||
private static Uri CreateGoogleMapsUri(string latitudeString, string longitudeString) | ||
{ | ||
return inputString != null && inputString.Trim() != ""; | ||
var uriString = string.Format( | ||
"https://www.google.com/maps/search/?api=1&query={0},{1}", | ||
latitudeString, | ||
longitudeString); | ||
return new Uri(uriString); | ||
} | ||
|
||
private static Uri CreateAppleMapsUri(string latitudeString, string longitudeString, string geoPointerTag) | ||
{ | ||
var uriString = string.Format( | ||
"http://maps.apple.com/?ll={0},{1}&q={2}", | ||
latitudeString, | ||
longitudeString, | ||
HttpUtility.UrlEncode(geoPointerTag)); | ||
return new Uri(uriString); | ||
} | ||
|
||
private static bool IsRunningOnIOS() | ||
{ | ||
return Device.RuntimePlatform == Device.iOS; | ||
} | ||
|
||
private static bool IsGeoPointValid(GeoPoint geoPoint) | ||
{ | ||
return geoPoint != null; | ||
} | ||
} | ||
} |