calling google maps/ios maps from corona

hi.

usually when i work with maps i call native.newMapView() for simple stuff.

if i want directions i would go for system.url route with http://…will call web version of  google map and will show it.

i tried a different approach today with 50% of success.

my code is this: 

local url="comgooglemaps:" local function getDirections() if not ( system.canOpenURL(url) ) then system.openURL("http://maps.apple.com/?saddr="..mylat..","..mylng.."&daddr="..lat..","..lng.."&dirflg=r") else system.openURL( url.."//?saddr="..mylat..","..mylng.."&daddr="..lat..","..lng.."&directionsmode=transit" ) end end

on IOS with google maps app installed it will open google maps like it should.

on IOS without google maps will open apple app like it should.

on android it will not detect the google maps app is installed. Even if it is, and will start to open maps from apple on browser…it detects thats a map i’m trying to open…half a second later closes apples map, opens google maps. 0%? of success because it should had open in the first place the app.

so on IOS all works like it should. on android not really. what i’m doing it wrong in android part?

do i need to go “intent” route on android?

regards,

carlos.

URL Schemes are for iOS. You will need Intents for Android. You should also check to see what platform you are on and call the different methods accordingly.

Rob

thanks Rob for the clarification.

what i did was:

local function getDirections() -- local appinstalled = false local url="comgooglemaps:" if ( system.getInfo( "platform" ) == "android") then -- local package\_android="com.google.android.apps.maps" -- local appIcon = display.newImage("android.app.icon://"..package\_android, 200,-200) -- if appIcon then -- display.remove(appIcon) -- appIcon = nil -- appinstalled = true -- else -- appinstalled = false -- end system.openURL("http://maps.google.com/maps?z=12&saddr="..mylat..","..mylng.."&daddr="..lat..","..lng.."&directionsmode=transit") elseif ( system.getInfo( "platform" ) == "ios") and ( system.canOpenURL(url) ) then system.openURL( url.."//?saddr="..mylat..","..mylng.."&daddr="..lat..","..lng.."&directionsmode=transit" ) elseif ( system.getInfo( "platform" ) == "ios") then system.openURL("http://maps.apple.com/?saddr="..mylat..","..mylng.."&daddr="..lat..","..lng.."&dirflg=r") end end

I removed the verification for android devices.

I guess android do that internally because when I call a “http://maps.google.com” it will open the native app not the browser version. i disabled the google maps on my device and it called the web version.

URL Schemes are for iOS. You will need Intents for Android. You should also check to see what platform you are on and call the different methods accordingly.

Rob

thanks Rob for the clarification.

what i did was:

local function getDirections() -- local appinstalled = false local url="comgooglemaps:" if ( system.getInfo( "platform" ) == "android") then -- local package\_android="com.google.android.apps.maps" -- local appIcon = display.newImage("android.app.icon://"..package\_android, 200,-200) -- if appIcon then -- display.remove(appIcon) -- appIcon = nil -- appinstalled = true -- else -- appinstalled = false -- end system.openURL("http://maps.google.com/maps?z=12&saddr="..mylat..","..mylng.."&daddr="..lat..","..lng.."&directionsmode=transit") elseif ( system.getInfo( "platform" ) == "ios") and ( system.canOpenURL(url) ) then system.openURL( url.."//?saddr="..mylat..","..mylng.."&daddr="..lat..","..lng.."&directionsmode=transit" ) elseif ( system.getInfo( "platform" ) == "ios") then system.openURL("http://maps.apple.com/?saddr="..mylat..","..mylng.."&daddr="..lat..","..lng.."&dirflg=r") end end

I removed the verification for android devices.

I guess android do that internally because when I call a “http://maps.google.com” it will open the native app not the browser version. i disabled the google maps on my device and it called the web version.