我想使用 in 中的两个变量 从 SMSaff.java
中MainActivity.java
获取 GPS 坐标。我尝试使用 Gson 并添加了另外两个类profil.java
,profilstatic.java
但我的应用程序不起作用。请帮我。
MainAvtivity.java
public class MainActivity extends Activity {
double lat1,lon1;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView view = new TextView(this);
Uri uriSMSURI = Uri.parse("content://sms/inbox");
Cursor cur = getContentResolver().query(uriSMSURI, null, null, null,null);
String sms = "";
while (cur.moveToNext()) {
String spn ="+21626938812";
String phNum =cur.getString(2);
if (spn.equals(phNum)){
sms +=cur.getString(12);
}
}
String a =sms.substring(0,10);
String b =sms.substring(11,21);
double lat = Double.parseDouble(a);
double lon = Double.parseDouble(b);
lat1=lat;
lon1=lon;
Profil profil = new Gson().fromJson("", Profil.class);
profil.setLat(lat1);
profil.setLon(lon1);
ProfilStatique.setProfil(profil);
Intent activity_main = new Intent(getApplicationContext(), aff.class) ;
startActivity(activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
aff.java
import java.util.ArrayList;
import java.util.List;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;
@SuppressWarnings("deprecation")
public class aff extends MapActivity {
double lat1,lon1;
Profil profil = ProfilStatique.getProfil();
MapView maMap;
MapController monControler;
double latitude = profil.getLat() ;
double longitude = profil.getLon() ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
maMap = (MapView)findViewById(R.id.myGmap);
maMap.setBuiltInZoomControls(true);
GeoPoint point = new GeoPoint (microdegrees(latitude),microdegrees(longitude));
MonOverlay object = new MonOverlay(getResources().getDrawable(R.drawable.marker_voisinage_rouge));
object.addPoint(point);
maMap.getOverlays().add(object);
maMap.setSatellite(true);
monControler = maMap.getController();
monControler.setZoom(12);
monControler.setCenter(point);
}
private int microdegrees (double value){
return (int)(value*1000000);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
public class MonOverlay extends ItemizedOverlay<OverlayItem>{
List<GeoPoint> points = new ArrayList<GeoPoint>();
public MonOverlay(Drawable arg0) {
super(boundCenterBottom(arg0));
// TODO Auto-generated constructor stub
}
@Override
protected OverlayItem createItem(int i) {
GeoPoint point = points.get(i);
return new OverlayItem(point,"titre","description");
}
@Override
public int size() {
return points.size();
}
public void addPoint (GeoPoint point){
this.points.add(point);
populate();
}
}
}
简介.java
public class Profil {
public double lat,lon;
public double getLat() {
return lat;
}
public void setLat(double lat) {
this.lat = lat;
}
public double getLon() {
return lon;
}
public void setLon(double lon) {
this.lon = lon;
}
}
ProfilStatic.java
public class ProfilStatique {
private static Profil profil = new Profil();
public static Profil getProfil() {
return profil;
}
public static void setProfil(Profil profil) {
ProfilStatique.profil = profil;
}
}