У меня есть намерение, которое выбирает местоположение с карт Google и отправляет значения двойной долготы и широты в другое намерение. В этой деятельности у меня есть фрагмент карты, который должен отображать местоположение на карте в соответствии с значениями широты и долготы, которые я получаю. Я правильно получаю значения удвоений для активности, но не показывает правильное местоположение. Я пробовал отлаживать весь день, но, поскольку нет ошибки, я не могу найти, что я делаю неправильно. Вот мой классНеправильное отображение местоположения при попытке установить карту из лат и длинных координат
public class Loc extends FragmentActivity{
double latitude;
double longitude;
TextView lat;
TextView lng;
EditText one;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.showmap);
lat = (TextView) findViewById(R.id.tv1);
lng = (TextView) findViewById(R.id.tv2);
one = (EditText) findViewById(R.id.et1);
// Receiving latitude from MainActivity screen
double latitude = getIntent().getDoubleExtra("lat", 0);
// Receiving longitude from MainActivity screen
double longitude = getIntent().getDoubleExtra("lng", 0);
String lats = String.valueOf(latitude);
String lngs = String.valueOf(longitude);
lat.setText(lats);
lng.setText(lngs);
LatLng position = new LatLng(longitude, latitude);
// Instantiating MarkerOptions class
MarkerOptions options = new MarkerOptions();
// Setting position for the MarkerOptions
options.position(position);
// Setting title for the MarkerOptions
options.title("Position");
// Setting snippet for the MarkerOptions
options.snippet("Latitude:"+latitude+",Longitude:"+longitude);
// Getting Reference to SupportMapFragment of activity_map.xml
SupportMapFragment fm = (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
// Getting reference to google map
GoogleMap googleMap = fm.getMap();
// Adding Marker on the Google Map
googleMap.addMarker(options);
// Creating CameraUpdate object for position
CameraUpdate updatePosition = CameraUpdateFactory.newLatLng(position);
// Creating CameraUpdate object for zoom
CameraUpdate updateZoom = CameraUpdateFactory.zoomBy(4);
// Updating the camera position to the user input latitude and longitude
googleMap.moveCamera(updatePosition);
// Applying zoom to the marker position
googleMap.animateCamera(updateZoom);
}
}
Это где я звоню этот класс
public class Map extends Activity {
Button ok;
WebView webview;
String q;
TextView add;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
TextView url = (TextView) findViewById(R.id.tvURL);
add = (TextView) findViewById(R.id.tvAddress);
Button done = (Button) findViewById(R.id.btnDone);
webview = (WebView) findViewById(R.id.webView1);
webview.setWebViewClient(new WebViewClient());
webview.getSettings().setJavaScriptEnabled(true);
//webview.loadUrl("http://maps.google.com/maps?" + "saddr=43.0054446,-87.9678884" + "&daddr=42.9257104,-88.0508355");
webview.loadUrl("https://goo.gl/maps/Fz0KJ");
//String url1 = uri.toString();
done.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
try{
String q1="";
String str = webview.getUrl();
//Uri uri = Uri.parse(str);
//uri.getQueryParameter(q1);
///Log.d("lats",q1);
String[] part1 = str.split(Pattern.quote("@"));
String[] part2 = part1[1].split(Pattern.quote(","));
double lat = Double.parseDouble(part2[0]);
double lon = Double.parseDouble(part2[1]);
add.setText(lat+","+lon);
final Intent yourIntent = new Intent(Map.this, Loc.class);
yourIntent.putExtra("lat", lat);
yourIntent.putExtra("lng", lon);
//setResult(101, yourIntent);
startActivity(yourIntent);
//finish();
}catch(NullPointerException ex){
System.out.println (ex.toString());
Toast.makeText(Map.this, "Slow internet. Please wait till the map loads", Toast.LENGTH_SHORT).show();
}
}
});
}
Сколько разного местоположения? Целевые и полученные координаты lat, lng были бы хороши. – Simas
Это показывает море недалеко от Гренландии. Мои длинные латы 1,532528,110,358054. Предполагается, что это Swinburne University, Sarawak, Malaysia –
Не могли бы вы сделать маркер маркера = googleMap.addMarker (options); 'и затем напечатать' marker.get position() '? – antonio