Android Question my location camera position

jchal

Active Member
Licensed User
Longtime User
i try the following code and i need some help b4a versio 6.8
B4X:
Dim cp As CameraPosition
    cp.Initialize(gmap.MyLocation.Latitude, gmap.MyLocation.Longitude, gmap.CameraPosition.Zoom)
    gmap.AnimateCamera(cp)

but i get the following error
 
Last edited:

jchal

Active Member
Licensed User
Longtime User
here it is
B4X:
#Region  Project Attributes
   #ApplicationLabel: GOOGLEMAPS Example
   #VersionCode: 1
   #VersionName:
   'SupportedOrientations possible values: unspecified, landscape or portrait.
   #SupportedOrientations: unspecified
   #CanInstallToExternalStorage: False
    #AdditionalJar: com.google.android.gms:play-services-maps

#End Region

#Region  Activity Attributes
   #FullScreen: False
   #IncludeTitle: True
#End Region

'Activity module
Sub Process_Globals

End Sub

Sub Globals
    Private gmap As GoogleMap
    Private MapFragment1 As MapFragment
  
  
    Private Panel1 As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
    If MapFragment1.IsGooglePlayServicesAvailable = False Then
        ToastMessageShow("Please install Google Play Services.", True)
    End If
  
    End Sub
  


Sub MapFragment1_Ready
    gmap = MapFragment1.GetMap
    Dim m1 As Marker = gmap.AddMarker(10, 30, "test")
    Dim lat,lon As Int
  
    m1.Snippet = "This is the snippet"
    Dim cp As CameraPosition
    lat = gmap.MyLocation.Latitude
    lon=gmap.MyLocation.Longitude
    cp.Initialize(lat, lon, 10)
    gmap.AnimateCamera(cp)
    'gmap.MoveCamera(cp)
    'Panel1.Visible = True
    'Dim cp As CameraPosition
    'cp.Initialize(gmap.MyLocation.Latitude, gmap.MyLocation.Longitude, 10)
    'gmap.MoveCamera(cp)
        'Dim cp As CameraPosition
        'cp.Initialize(10, 30, gmap.CameraPosition.Zoom)
        'gmap.AnimateCamera(cp)
  
End Sub
B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="14"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)

AddApplicationText(<meta-data
  android:name="com.google.android.maps.v2.API_KEY"
  android:value="AIzazzzzzzzzzzzzzzzzzzzzzz"/>
   <meta-data android:name="com.google.android.gms.version"
   android:value="@integer/google_play_services_version" />
)
'End of default text.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
lat = gmap.MyLocation.Latitude
lon=gmap.MyLocation.Longitude
Did you marked the Checkbox in MapFragment (in designer) for Own Location enabled.


Otherwise you can enable it at runtime.
B4X:
Sub MapFragment1_Ready
    Log("MapReady()")
    gmap = MapFragment1.GetMap
    gmap.MyLocationEnabled = True

Which B4A Version are you using?


if you use B4A 6+ then it should be only
B4X:
AddApplicationText(
<meta-data
  android:name="com.google.android.geo.API_KEY"
  android:value="AIzaSxxxxxxxxx "/>
)
plus the base-snippet from firebase-integration (which should be
B4X:
'************ Google Play Services Base ************
AddApplicationText(
   <activity android:name="com.google.android.gms.common.api.GoogleApiActivity"
  android:theme="@android:style/Theme.Translucent.NoTitleBar"
  android:exported="false"/>
    <meta-data
  android:name="com.google.android.gms.version"
  android:value="@integer/google_play_services_version" />
)
'************ Google Play Services Base (end) ************

With other words. Check you GoogeMaps implementation.
 
Last edited:
Upvote 0

jchal

Active Member
Licensed User
Longtime User
DonManfred it is not working
when it comes to line which is line 48
B4X:
 lat = gmap.MyLocation.Latitude
it crashes and the log is
if i remove the
B4X:
Dim cp As CameraPosition
    lat = gmap.MyLocation.Latitude
    lon=gmap.MyLocation.Longitude
    cp.Initialize(lat, lon, 10)
    gmap.AnimateCamera(cp)
everithing works
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
this is the down load link as i canot send larger files than 512kb
In the IDE under File->Export as zip
This is the right way to export a project.

As you can see; your project is just 8kb in size.

PD: Please note that MyLocation is only available when outside.... At least it is working for me only when i have GPS Signal....
 

Attachments

  • maps.zip
    8.5 KB · Views: 391
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…