iOS Question [SOLVED] Google Maps Library Problem - Getting visible bounds from mapview

mesutaslan

Member
Licensed User
Longtime User
How can i get Bounds locations from

B4X:
- (NSObject*)coordinateBoundsFromProjection:(GMSProjection*) p

when i tried to access location via
B4X:
Dim bounds As NativeObject = gmapEx.GetVisibleBounds
            Dim ne As Location = bounds.GetField("northEast")

ide says :
Expected: CLLocation, object type: NSConcreteValue
 

mesutaslan

Member
Licensed User
Longtime User
end also when i try to access northEast object in GMSCoordinateBounds to access latitude or longitude with

B4X:
            Dim bounds As NativeObject = gmapEx.GetVisibleBounds
            Dim ne As NativeObject = bounds.GetField("northEast")
            Log(ne.GetField("latitude"))

it says :
[<NSConcreteValue 0x7d7b2ca0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key latitude.
 
Upvote 0

mesutaslan

Member
Licensed User
Longtime User
B4X:
If gmap.IsInitialized Then
            Dim bounds As NativeObject = gmapEx.GetVisibleBounds
            Log(bounds)
            Dim ne As NativeObject = bounds.GetField("northEast")
            Log(ne.GetField("latitude"))
        End If

ne object or ne.getfield raises error

result of log(bounds) :

<B4INativeObject: <GMSCoordinateBounds: 0x7aef43e0>>
 
Upvote 0

mesutaslan

Member
Licensed User
Longtime User
also output of log(ne) is

<B4INativeObject: <3218d388 05f93040 0000a0d8 7f154040>>


I am using local builder and google maps lib version :
Google Maps SDK for iOS version: 2.2.30010.0
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
CLLocationCoordinate2D is a struct. You must use OBJC code to extract it.

Add this code to the OBJC section in GoogleMapExtra:
B4X:
- (void)getLatLngFromBounds:(GMSCoordinateBounds*) bounds :(B4ILatLng*) northEast :(B4ILatLng*) southWest {
   [northEast Initialize:bounds.northEast.latitude :bounds.northEast.longitude];
   [southWest Initialize:bounds.southWest.latitude :bounds.southWest.longitude];
}

Add this B4i code to the class:
B4X:
Public Sub GetBoundsNE_SW (bounds As Object) As LatLng()
   Dim ne, sw As LatLng
   no.RunMethod("getLatLngFromBounds:::", Array(bounds, ne, sw))
   Return Array As LatLng(ne, sw)
End Sub

Call it like this:
B4X:
Sub gmap_Click (Point As LatLng)
   Dim bounds As Object = gextra.GetVisibleBounds
   Dim ne_sw() As LatLng = gextra.GetBoundsNE_SW(bounds)
   Log(ne_sw(0))
   Log(ne_sw(1))
End Sub
 
Upvote 0

mesutaslan

Member
Licensed User
Longtime User
CLLocationCoordinate2D is a struct. You must use OBJC code to extract it.

Add this code to the OBJC section in GoogleMapExtra:
B4X:
- (void)getLatLngFromBounds:(GMSCoordinateBounds*) bounds :(B4ILatLng*) northEast :(B4ILatLng*) southWest {
   [northEast Initialize:bounds.northEast.latitude :bounds.northEast.longitude];
   [southWest Initialize:bounds.southWest.latitude :bounds.southWest.longitude];
}

Add this B4i code to the class:
B4X:
Public Sub GetBoundsNE_SW (bounds As Object) As LatLng()
   Dim ne, sw As LatLng
   no.RunMethod("getLatLngFromBounds:::", Array(bounds, ne, sw))
   Return Array As LatLng(ne, sw)
End Sub

Call it like this:
B4X:
Sub gmap_Click (Point As LatLng)
   Dim bounds As Object = gextra.GetVisibleBounds
   Dim ne_sw() As LatLng = gextra.GetBoundsNE_SW(bounds)
   Log(ne_sw(0))
   Log(ne_sw(1))
End Sub


YOU ROCK !!!
 
Upvote 0
Top