1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
|
package com.example.geolocalisation;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMapClickListener;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.maps.GeoPoint;
public class MainActivity extends FragmentActivity implements LocationListener {
private final String NAMESPACE = "http://ws.userlogin.com";
private final String URL = "http://192.168.1.4:8085/Login/services/Login?wsdl";
private final String SOAP_ACTION = "http://ws.userlogin.com/insertData";
private final String METHOD_NAME = "insertData";
private TextView l,l1;
private GoogleMap myMap;
private GeoPoint p;
private Spinner geo_type;
private LocationManager Lm;
private LocationListener ll;
private int x=0;
private double lat,longi;
private Button valider;
public String latitude,longitude,str;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SupportMapFragment myMapFragment = (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map); //stokage de la map
myMap = myMapFragment.getMap(); //chargement de la map
myMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN); //chargement du type de la map
myMap.setMyLocationEnabled(true); // afficher la position de l'utilisateur
myMap.getUiSettings().setCompassEnabled(true);
Lm=(LocationManager)getSystemService(LOCATION_SERVICE);
l=(TextView)findViewById(R.id.textView1);
l1=(TextView)findViewById(R.id.textView2);
valider=(Button)findViewById(R.id.button1);
myMap.setOnMapClickListener(new OnMapClickListener() {
@Override
public void onMapClick(LatLng point) {
Toast.makeText(getApplicationContext(), point.toString(), Toast.LENGTH_SHORT).show();
if(x==0){
Marker mark=myMap.addMarker(new MarkerOptions().position(point).title("Votre magasin est ici"));
lat=mark.getPosition().latitude;
longi=mark.getPosition().longitude;
l.setText(Double.toString(lat));
l1.setText(Double.toString(longi));
x=1;
}
else {
myMap.clear();
Marker mark=myMap.addMarker(new MarkerOptions().position(point).title("Votre magasin est ici"));
lat=mark.getPosition().latitude;
longi=mark.getPosition().longitude;
l.setText(Double.toString(lat));
l1.setText(Double.toString(longi));
}
myMap.animateCamera(CameraUpdateFactory.newLatLng(point));
}
});
geo_type=(Spinner)findViewById(R.id.type_affichage);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,R.array.type_affichage,android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
geo_type.setAdapter(adapter);
geo_type.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
String ty=geo_type.getSelectedItem().toString();
if (ty.equals("Terrain")){
myMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
}
if (ty.equals("Hybrid")){
myMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
}
if (ty.equals("Normal")){
myMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
valider.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
insere();
}
});
}
private void insere(){
new Thread(new Runnable() {
@Override
public void run() {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
latitude=l.getText().toString();
longitude=l1.getText().toString();
PropertyInfo unameProp =new PropertyInfo();
unameProp.setName("Latitude");//Define the variable name in the web service method
unameProp.setValue(latitude);//set value for userName variable
unameProp.setType(String.class);//Define the type of the variable
request.addProperty(unameProp);//Pass properties to the variable
PropertyInfo unameProp1 =new PropertyInfo();
unameProp1.setName("Longitudee");//Define the variable name in the web service method
unameProp1.setValue(longitude);//set value for userName variable
unameProp1.setType(String.class);//Define the type of the variable
request.addProperty(unameProp1);//Pass properties to the variable
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try{
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
str=response.toString();
}
catch(Exception e){
}
runOnUiThread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
}
});
}
}).start();
}
@Override
public void onLocationChanged(Location location) {
LatLng latlng= new LatLng(location.getLatitude(), location.getLongitude());
myMap.animateCamera(CameraUpdateFactory.newLatLng(latlng));
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
} |
Partager