PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV Mobile 2024 → Manage Map Control in JAVA
Manage Map Control in JAVA
Débuté par Antonino Neri, 16 jan. 2017 17:13 - 8 réponses
Posté le 16 janvier 2017 - 17:13
Hi guys,

I would like to know how I can manage a MAP CONTROL, in an Android app, using JAVA instead of WL functions that are limited and do not fulfill my needs.

I would like to start with something really simple like adding a marker on a map so I try this code:



import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public static void InitializeGoogleMap()
{
GoogleMap map = getView("MAP_EVENTS");

// Add a marker in Sydney and move the camera
LatLng sydney = new LatLng(-34, 151);
map.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
map.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}



but when I compile the app I get an error on the very first line: GoogleMap map = getView("MAP_EVENTS").

Does anyone know how this can be done?

Thank you all.


Kindest Regards,
Antonino
Posté le 10 octobre 2017 - 08:29
Hi,

Maybe this code will help for anyone whose trying to customise Google map. This is just a sample but it works !!!

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapView;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.maps.model.Marker;
import android.widget.Toast;

public static void CustomMap()
{
MapView mapView = (MapView) getView("CARTE_Accueil");
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(GoogleMap googleMap) {
LatLng PARIS = new LatLng(48.858093, 2.294694);

//ajoute un marker sur Paris
googleMap.addMarker(new MarkerOptions().title("Paris").position(PARIS));

//centre la google map sur Paris (avec animation de zoom)
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(PARIS, 15));
googleMap.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);

googleMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {
Toast.makeText(getContexteApplication(),marker.getTitle(),Toast.LENGTH_LONG).show();
}
});
}
});
}
Membre enregistré
20 messages
Popularité : +1 (1 vote)
Posté le 11 octobre 2017 - 13:29
Hi Philippe

I am new in Windev Mobile/Java and I tried to use your precedent code.

I have created a window with a map "CARTE_Accueil".
I have create a global procedure (java) with your code but how I can use this code to display a map?

Till now, in Windev Mobile I have succeeded to display a map with some markers

POUR i = 1 _A_ TableOccurrence(TABLE_Adresse)
SI PAS (TABLE_Adresse.COL_Latitude[i] = 0 ET TABLE_Adresse.COL_Longitude[i] = 0) ALORS

nPos..Latitude = TABLE_Adresse.COL_Latitude[i]
nPos..Longitude = TABLE_Adresse.COL_Longitude[i]

CarteAffichePosition(CARTE_Points, nPos)

tabMMark[i]..Position = nPos
CarteAjouteMarqueur(CARTE_Points, tabMMark[i])
FIN
FIN
CARTE_Points..Zoom = zoomAdapteTaille

My code is displaying a map but I need something else : when user moves or enlarges the map, I want to obtain the coordinates of the markers which are still visible in the map.

With Windev Mobile I didn't succeed and I thought that I could use Java but I don't know from where to start.

Thanks for any advice

--
Issa Bej
Membre enregistré
2 566 messages
Popularité : +222 (260 votes)
Posté le 11 octobre 2017 - 13:59
Hi Issa,

You just have to call the procedure customMap() somewhere in your code, when the window is initializing for exemple.

--
Cordialement,

Philippe SAINT-BERTIN
Géode Informatique
Membre enregistré
20 messages
Popularité : +1 (1 vote)
Posté le 11 octobre 2017 - 14:52
Thank you, Philippe!

I have already tried as you said.
I have received error
L'appel de code natif n'est pas disponible.
Code erreur : 1185
Niveau : erreur fatale


After that I saw an answer from Fabrice (Harrari)
you are in test mode...

Test mode is a SIMULATION of the android system, but does NOT include a
JAVA engine (there is no java complation before the simulation starts)...

therefore, anything in java can be test only after compiling, on a real
android hardware

and I tried to generate the application without including any files or libraries. I have filled only my google API key.
the error is :
Message d'erreur système :
The parameter is incorrect.

----- Sous-erreur n°1 -----
Echec de la création de l'application Android .

Ligne de commande :  assembleDebug -b "F:\Mes Projets 22 WindevMobile\Mon_ProjetTestCarte\Android\Generation\build.gradle"

Erreur retournée :


Do you have any idea about what is not correct?
Thanks a lot

--
Issa Bej
Membre enregistré
2 566 messages
Popularité : +222 (260 votes)
Posté le 11 octobre 2017 - 16:25
Sorry no idea...;(

--
Cordialement,

Philippe SAINT-BERTIN
Géode Informatique
Membre enregistré
2 566 messages
Popularité : +222 (260 votes)
Posté le 12 octobre 2017 - 14:13
You must have at least these permissions:





and these functionalities:





--
Cordialement,

Philippe SAINT-BERTIN
Géode Informatique
Membre enregistré
20 messages
Popularité : +1 (1 vote)
Posté le 12 octobre 2017 - 15:21
Hi Philippe!

Thank you for answer.

I have found a solution here,
https://forum.pcsoft.fr/en-US/pcsoft.fr.windevmobile/28657-execution-gradle-28668/read.awp

I have replaced version of Gradle.

And after this, it was necessary also to enable in Google Api Console "Google API Android Maps" and now everything it's ok.
My first test worked :).

Best regards

--
Issa Bej
Membre enregistré
2 566 messages
Popularité : +222 (260 votes)
Posté le 12 octobre 2017 - 16:16
On the other hand you can't use every methods of a class. For example you can't use the setTag or getID method of Marker class. I have an error

error: cannot find symbol
import com.google.android.gms.maps.model.MapStyleOptions;
symbol: class MapStyleOptions
location: package com.google.android.gms.maps.model

error: cannot find symbol
appelProcedureWL("FEN_Menu.pl_SetIDMarqueur",marqueur.getID(),Integer.parseInt(Valeurs[3])); ^
symbol: method getID()
location: variable marqueur of type Marker

error: cannot find symbol
Toast.makeText(getContexteApplication(),String.valueOf(appelProcedureWL_int("FEN_Menu.pl_GetIDMarqueur",marker.getID))),Toast.LENGTH_LONG).show();
symbol: method getID()
location: variable marker of type Marker

3 errors
FAILED

Waiting for PC Soft to tell me if it's possible or not. If not then I switch to Xamarin

--
Cordialement,

Philippe SAINT-BERTIN
Géode Informatique