je suis un debutant en android et cherche quelqu'un pour m'aider
le probleme est :comment trouver la position de station Bus sur un fragment maps de telephone android
avec:
base mysql :table car(id,description,name,lat,long)
bus.php : web service pour
activity :MapsActivity
classe java(Bus,Busresponse,retrofitclient)
interface :Api
package net.simplifiedcoding.my;
import androidx.fragment.app.FragmentActivity;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import android.os.Bundle;
import android.util.Log;
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 class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
public void findPosition(){
try{
Call<BusResponse> call= RetrofitClient.getInstance().getApi().getBus();
call.enqueue(new Callback<BusResponse>() {
@Override
public void onResponse(Call<BusResponse> call, Response<BusResponse> response) {
BusResponse busResponse = response.body();
LatLng pos =new LatLng(busResponse.getBus().getLat(),busResponse.getBus().getLong());
String place=busResponse.getBus().getDescription();
mMap.addMarker(new MarkerOptions()
.position(pos)
.title(place)
);
mMap.moveCamera(CameraUpdateFactory.newLatLng(pos));
mMap.animateCamera(CameraUpdateFactory.zoomIn());
mMap.animateCamera(CameraUpdateFactory.zoomTo(10),2500,null);
}
@Override
public void onFailure(Call<BusResponse> call, Throwable t) {
}
});}
catch (Exception e){
Log.d("Mp",e.getLocalizedMessage())
; }
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
}
}
package net.simplifiedcoding.my;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
public class RetrofitClient {
private static final String BASE_URL = "http://192.168.43.157/";
private static RetrofitClient mInstance;
private Retrofit retrofit;
private RetrofitClient() {
retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
public static synchronized RetrofitClient getInstance() {
if (mInstance == null) {
mInstance = new RetrofitClient();
}
return mInstance;
}
public Api getApi(){
return retrofit.create(Api.class);
}
}
package net.simplifiedcoding.my;
import retrofit2.Call;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.POST;
public interface Api {
@POST("/car.php")
Call<BusResponse> getBus();
}
package net.simplifiedcoding.my;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Bus {
@SerializedName("name")
@Expose
private String name;
@SerializedName("description")
@Expose
private String description;
@SerializedName("long")
@Expose
private Double _long;
@SerializedName("lat")
@Expose
private Double lat;
@SerializedName("id")
@Expose
private String id;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Double getLong() {
return _long;
}
public void setLong(Double _long) {
this._long = _long;
}
public Double getLat() {
return lat;
}
public void setLat(Double lat) {
this.lat = lat;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
package net.simplifiedcoding.my;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class BusResponse {
@SerializedName("bus")
@Expose
private Bus bus;
public Bus getBus() {
return bus;
}
public void setBus(Bus bus) {
this.bus = bus;
}
}
<?php
require_once ('DbConnect.php');
error_reporting(0);
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
//if (isset($_GET['email']) && isset($_GET['password'])){
// username and password sent from link
$result = mysql_query("SELECT * FROM car ");
while ($row = mysql_fetch_array($result))
{
// temp user array
$output[]=$row;
print(json_encode($output));
}
mysqli_close($con);
}
?>
- Edité par massoud jarray 15 janvier 2020 à 13:50:10
comment trouver la position de station Bus
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.