Google and Apple Maps with Delphi XE4
2014-05-12 16:33
423 查看
http://www.glennstephens.com.au/2013/06/google-and-apple-maps-with-delphi-xe4/
If you follow the iPhone Maps, one you are probably lost, but two you know that Google Maps is a much better product. What if you want to use Google Maps, and if its not installed use Apple Maps. Luckily there is a way.
Much of the interprocess communication on the iOS can be done with URLs, you can register a custom URL scheme which is what Facebook does. Google Maps uses this ability as does Apple Maps so we can use it to your benefit.
In the Apple.Utils unit you will find in Samples\Delphi\RTL\CrossPlatform Utils there is a function called SharedApplication which returns the instance of UIApplication. UIApplication is an very handy tip, you can use the setApplicationIconBadgeNumber() method to set the number that appears on your App Icon, you can use the setNetworkActivityIndicatorVisible() method to set the network progress indicator at the top of the screen, it really is quite useful. The unit also has an OpenURL function which is very handy; think of it like the iOS equivilant of ShellExecute and you’ll be right.
So for checking if you have Google Maps you can use the canOpenURL method of UIApplication to determine if the URL can in fact be opened.The following will get the URLs for the various map systems for a lat/long for Google and Apple respectivly.
function TfrmMyApp.GetGoogleMapsUrl: string;
begin
Result := Format(‘comgooglemaps://?center=%s,%s&zoom=14′,
[LastLocation.Latitude.ToString, LastLocation.Longitude.ToString]
);
end;
function TfrmMyApp.GetAppleMapsUrl: string;
begin
Result := Format(‘http://maps.apple.com/?ll=%s,%s’,
[LastLocation.Latitude.ToString, LastLocation.Longitude.ToString]);
end;
and then to check try and open the Google First, and then Apple Maps if you really have to you would just need the following.
if SharedApplication.canOpenURL(StringToNSUrl(GetGoogleMapsUrl)) then
OpenURL(GetGoogleMapsUrl)
else
OpenURL(GetAppleMapsUrl);
This example is based on the lat/long only and there are plenty of ways to create the Maps URLs from things like getting directions, passing in an address. For a complete list for Google Maps and Apple Maps, check out:
http://developers.google.com/maps/documentation/ios/urlscheme
http://developer.apple.com/library/ios/#featuredarticles/iPhoneURLScheme_Reference/Articles/MapLinks.html
Enjoy.
If you follow the iPhone Maps, one you are probably lost, but two you know that Google Maps is a much better product. What if you want to use Google Maps, and if its not installed use Apple Maps. Luckily there is a way.
Much of the interprocess communication on the iOS can be done with URLs, you can register a custom URL scheme which is what Facebook does. Google Maps uses this ability as does Apple Maps so we can use it to your benefit.
In the Apple.Utils unit you will find in Samples\Delphi\RTL\CrossPlatform Utils there is a function called SharedApplication which returns the instance of UIApplication. UIApplication is an very handy tip, you can use the setApplicationIconBadgeNumber() method to set the number that appears on your App Icon, you can use the setNetworkActivityIndicatorVisible() method to set the network progress indicator at the top of the screen, it really is quite useful. The unit also has an OpenURL function which is very handy; think of it like the iOS equivilant of ShellExecute and you’ll be right.
So for checking if you have Google Maps you can use the canOpenURL method of UIApplication to determine if the URL can in fact be opened.The following will get the URLs for the various map systems for a lat/long for Google and Apple respectivly.
function TfrmMyApp.GetGoogleMapsUrl: string;
begin
Result := Format(‘comgooglemaps://?center=%s,%s&zoom=14′,
[LastLocation.Latitude.ToString, LastLocation.Longitude.ToString]
);
end;
function TfrmMyApp.GetAppleMapsUrl: string;
begin
Result := Format(‘http://maps.apple.com/?ll=%s,%s’,
[LastLocation.Latitude.ToString, LastLocation.Longitude.ToString]);
end;
and then to check try and open the Google First, and then Apple Maps if you really have to you would just need the following.
if SharedApplication.canOpenURL(StringToNSUrl(GetGoogleMapsUrl)) then
OpenURL(GetGoogleMapsUrl)
else
OpenURL(GetAppleMapsUrl);
This example is based on the lat/long only and there are plenty of ways to create the Maps URLs from things like getting directions, passing in an address. For a complete list for Google Maps and Apple Maps, check out:
http://developers.google.com/maps/documentation/ios/urlscheme
http://developer.apple.com/library/ios/#featuredarticles/iPhoneURLScheme_Reference/Articles/MapLinks.html
Enjoy.
相关文章推荐
- Beginning Google Maps Applications with Rails and Ajax: From Novice to Professional
- Visualisation with R and Google Maps
- Can The Jeopardy Challenge Help IBM Compete With Apple And Google?
- Beginning Google Maps Applications with PHP and Ajax: From Novice to Professional
- Beginning Google Maps Applications with Rails and Ajax From Novice to Professional - Chapter One
- Beginning Google Maps Applications with Rails and Ajax: From Novice to Professional
- Detect a point is inside a polygon with google maps
- Go Google: 20 Ways to Reach More Customers and Build Revenue with Google Business Tools
- 5-Local Notifications and Push Notifications--Provider Communication with Apple Push Notification Service
- Example of Using Google Maps Service and GPS in Android
- 与朋友分享你的位置-Google Maps with Latitude
- Dashboards in R with Shiny and GoogleVis
- Google Maps API and WMS Servers
- Hacking Google Maps and Google Earth
- Google 面试题:Java实现用最大堆和最小堆查找中位数 Find median with min heap and max heap in Java
- Google, with new Pixel and camera, is serious about devices
- 苹果脚本- Send SMS to Messages and run commands with AppleScript
- Hacking Google Maps and Google Earth (ExtremeTech)
- 5-Local Notifications and Push Notifications--Provider Communication with Apple Push Notification Service
- Creating Heat Maps with Bing Maps and Dynamics CRM