PC SOFT
ONLINE REPOSITORY
FOR WINDEVWEBDEV AND WINDEV MOBILE

Home |  | Sign in | English US
WM Geo-Localization Exemplo do Google Maps
Published by Boller
in the category Tools
New features



Description
WM Geo-Localization Exemplo do Google Maps

// Summary: Displays the address corresponding to the GPS position passed in parameter
// Syntax:
//DisplayAddress (<GPSPosition> is geoPosition)
//
// Parameters:
// GPSPosition (geoPosition): GPS position
// Return value:
// None

PROCEDURE DisplayAddress(GPSPosition is a geoPosition)

MyAddress is an Address
arrAddresses is array of Address
IF geoGetAddress(GPSPosition..Latitude + "," + GPSPosition..Longitude, arrAddresses) = False THEN
IF ErrorOccurred THEN
STC_City = "Unknown address"
STC_City..Visible = True
RETURN
END
END

MyAddress = arrAddresses[1]

STC_City = MyAddress..City
STC_City..Visible = True

STC_Street = MyAddress..Street
STC_Street..Visible = True

--------------------------------------------------------------------

/// Summary: Procedure called whenever the GPS status is modified
// Syntax:
//_ChangeGPSStatus (<nStatus>)
//
// Parameters:
// nStatus: New GPS status
// Return value:
// None

PROCEDURE _ChangeGPSStatus(nStatus)

// Ignores the call if the status was not modified
IF gnCurrentStatus = nStatus THEN
RETURN
END

// Stores the current status
gnCurrentStatus = nStatus


SWITCH nStatus
CASE gpsEnabled // the provider was enabled by the user.
GetAddress()

CASE gpsDisabled // the provider was disabled by the user.

CASE gpsOffService // the provider is off service.

CASE gpsUnavailable // the provider is temporarily unavailable.

CASE gpsAvailable // the provider is available.
GetAddress()
END


-------------------------------------------------------------------------------

// Summary: Indicates whether the store is found at the address passed in parameter
// Syntax:
//[ <Result> = ] bStoreAtThisAddress (<SpecifiedAddress> is Address)
//
// Parameters:
// SpecifiedAddress (Address): Search address
// Return value:
// boolean: True if the store is at the specified address, False otherwise
//
PROCEDURE bStoreAtThisAddress(InputAddress is an Address)

IF InputAddress..City <> "" _AND_ Upper(InputAddress..City) = Upper(Store.City) THEN
IF InputAddress..Street = "" THEN
RESULT True
ELSE
IF Upper(InputAddress..Street) = Upper(Store.Address) THEN
RESULT True
END
END

END

RESULT False

-----------------------------------------------------------------------

// Summary: Process called during the click on a marker
// Syntax:
//ClickMarker (<CurrentMarker> is Marker)
//
// Parameters:
// CurrentMarker (Marker):
// Return value:
// None

PROCEDURE ClickMarker(CurrentMarker is a Marker)

//Modify the image of the marker that was clicked
CurrentMarker..Image = "POI.gif"
MapModifyMarker(MAP_Position,CurrentMarker)

//Display the store information
STC_MapMarkerName = ExtractString(CurrentMarker..Description, 1, TAB)
STC_MapMarkerAddress = ExtractString(CurrentMarker..Description, 2, TAB)
STC_MapMarkerDistance = ExtractString(CurrentMarker..Description, 3, TAB)

//The previous marker clicked is restored to its initial status
IF PreviousMarker <> Null THEN
PreviousMarker..Image = "MarkerRest.gif"
MapModifyMarker(MAP_Position,PreviousMarker)
END

//Store the "future previous marker"
PreviousMarker = CurrentMarker


-----------------------------------------------------------------------------------------------------------

// Summary: Displays the window plane with the map

PROCEDURE DisplayMapPlane()

MyWindow..Plane = 3

//Position on the 1st marker by default, otherwise it is the marker that was clicked in the looper
TheMarker is a Marker = garrStores[1]
ClickMarker(TheMarker)


MAP_Position..Zoom = zoomAdaptSize

------------------------------------------------------------------------------------------------------

// Summary: Converts a distance in meters into a distance in everyday language
// Syntax:
//[ <Result> = ] DistanceToString (<rDistance>)
//
// Parameters:
// rDistance: Distance in meters
// Return value:
// UNICODE string: String with the distance in m or km ; according to the value

PROCEDURE DistanceToString(rDistance)


sDistance is string
IF rDistance > 999 THEN
sDistance = StringBuild( "%1 km", Round(rDistance /1000,1))
ELSE
sDistance = StringBuild( "%1 m", Round(rDistance))
END

RESULT sDistance

------------------------------------------------------------------------------------

// Summary: Finds the stores located at the specified address
PROCEDURE FindA()

//Reinitialize the variables used for the search
Reinitialization()

//Perform a search at the specified address, therefore don't display a distance in relation to another address
LOOP_ListMarkers.STC_Distance..Visible = False

//Retrieve the GPS position of the specified address
arrAddresses is array of Address
IF geoGetAddress(EDT_Or, arrAddresses) = False THEN
IF ErrorOccurred THEN
Error(ErrorInfo())
RETURN
END
END
InputAddress is an Address = arrAddresses[1]
gPositionA is a geoPosition = InputAddress..Position

//Browse the stores of the database
FOR EACH Store

//If the store is at the address
IF bStoreAtThisAddress(InputAddress) = True THEN

//Add a marker for this store in the map
AMarker is a Marker
AMarker..Position..Latitude = Store.Latitude
AMarker..Position..Longitude = Store.Longitude
AMarker..ActionClick = ClickMarker
AMarker..Description = Store.Lastname + TAB + Store.Address + SPC + Store.City
MapAddMarker(MAP_Position, AMarker)

//Store the store in the array
nSubscript is int
nSubscript = ArrayAdd(garrStores, AMarker)

//Add the store into the looper
LooperAddLine(LOOP_ListMarkers, Store.Lastname, Store.Address, Store.City,0, "", nSubscript )

END
END

//Indicate the number of answers found
STC_NbAnswers = StringBuild(" %1 answer(s)",LooperCount(LOOP_ListMarkers))

//Centers the map on the specified address
MapDisplayPosition(MAP_Position, gPositionA)

STC_RemindSearch2 = TAB + "at " + EDT_Or
STC_RemindSearch1 = TAB + "at " + EDT_Or

MyWindow..Plane = 2


-----------------------------------------------------------------------------------------------

// Summary: Finds the stores located near the specified address >> the search radius can be modified, cf "CST_DISTANCE" constant assigned to 10 kms
// Syntax:
//FindNearBy (<PositionForSearchRadius> is geoPosition)
//
// Parameters:
// PositionForSearchRadius (geoPosition): Position around which the search must be performed
// Return value:
// None

PROCEDURE FindNearBy(PositionForSearchRadius is a geoPosition)

//Reinitialize the variables used for the search
Reinitialization()

//Perform a "nearby" search, therefore display the distance between the stores found and the address specified for the search
LOOP_ListMarkers.STC_Distance..Visible = True

//Browse the stores of the database
StorePosition is a geoPosition
FOR EACH Store

//What is the distance between the store and the specified address
StorePosition..Latitude = Store.Latitude
StorePosition..Longitude = Store.Longitude
rDistance is real = geoDistance(StorePosition, PositionForSearchRadius)

//If the distance is less than 10 kms, for example
IF rDistance < CST_DISTANCE THEN

sDistance is string = DistanceToString(rDistance)

//Add a marker for this store in the map
AMarker is a Marker
AMarker..Position = StorePosition
AMarker..ActionClick = ClickMarker
AMarker..Description = Store.Lastname + TAB + Store.Address + SPC + Store.City + TAB + sDistance
MapAddMarker(MAP_Position, AMarker)

//Store the store in the array
nSubscript is int
nSubscript = ArrayAdd(garrStores, AMarker)
IF nSubscript <0 THEN
Error("The addition failed")
END
//Add the store into the looper
LooperAddLine(LOOP_ListMarkers, Store.Lastname, Store.Address, Store.City, rDistance, sDistance, nSubscript)

END
END

//Sort the looper according to the distance from the marker
LooperSort("ATT_DistanceValue")

//Indicate the number of answers found
STC_NbAnswers = StringBuild(" %1 answer(s)",LooperCount(LOOP_ListMarkers))

// Uncomment the following line to center the map on the position around which the search must be performed.
// In this example, display the map by taking all the markers into account and apply a zoom and an alignment according to the markers.
//MapDisplayPosition(MAP_Position, PositionForSearchRadius)

MyWindow..Plane = 2


-----------------------------------------------------------------------------------------

// Summary: Retrieves the GPS position of the device
// Syntax:
//[ <Result> = ] GetAddress ()
//
// Parameters:
// None
// Return value:
// boolean: True if the position was retrieved, False otherwise

PROCEDURE GetAddress()

//Informs the user that the search for his position is in progress
CTPL_Position.STC_CurrentSearch..Visible = True

//Display the current address
gMyCurrentPosition = GPSGetPosition()
CTPL_Position.DisplayAddress(gMyCurrentPosition)


RESULT True


CASE ERROR:
CTPL_Position.STC_CurrentSearch..Visible = True
CTPL_Position.STC_CurrentSearch = "Unknown position"
RESULT False

END :
//The search is completed
CTPL_Position.STC_CurrentSearch..Visible = False


-----------------------------------------------------------------------------------------------------------------

// Summary: Reinitialize the variables used for the search

PROCEDURE Reinitialization()

//Of the looper
LooperDeleteAll(LOOP_ListMarkers)

//Of the map with its markers
MapDeleteAll(MAP_Position)

//Of the array that stores the markers
ArrayDeleteAll(garrStores)

-----------------------------------------------------------------------------------

PROCEDURE WIN_Menu()

gnCurrentStatus is int //Status of GPS
gMyCurrentPosition is a geoPosition //Current GPS position

garrStores is array of Marker //Table of stores found
PreviousMarker is a Marker

gbFollowMove is boolean


MyWindow..Plane = 1
GR_Elsewhere..Visible = False


// Initialize the GPS
// Pass via the relevant provider (satellite or triangulation)
GPSInitParameter(gpsAuto)


// Is the GPS enabled?
IF GPSStatus() <> gpsEnabled THEN
Error("The GPS will not operate.","Enable it to access this application.")
ELSE
_ChangeGPSStatus(GPSStatus())
END


// Branch a callback procedure to be called when the status of the GPS changes
GPSStatus(_ChangeGPSStatus)



Illustrations, screen shots
none
none
User reviews
(To evaluate this resource, click 'Write a review')
Boller
PROCEDURE GPS_BuscaEndereco()

//Site Here Maps = https://developer.here.com/projects/PROD-1a48d00b-5e35-4f20-b50e-72d5dd4f77de

//glo_GpsLatitude = -25.2548
//glo_GpsLongitude = -49.1615

ApiKeyHere is string = "I_FQBhS2Odl8ZHLbLu_cPQzEh2J692-0I27qMgxx8GM"
Url is string = "https://revgeocode.search.hereapi.com/v1/revgeocode?at="+glo_GpsLatitude+","+glo_GpsLongitude+"&apiKey="+ApiKeyHere
Res is string = ""

ok is boolean = HTTPRequest(Url)

JsonHere is JSON = HTTPGetResult()

IF ok=True THEN
Res = JsonHere.items[1].address.label
ELSE
Res = ""
END

RETURN Res