내 앱 내부에 Google지도를 구현하고 String을 위도와 경도로 변환하려고 시도하고 있습니다 (예 : "USA New York -> 2345.423423"). 저는 인터넷에서 검색을했고, 위도와 경도를 String으로 변환하는 많은 예제를 발견했습니다. 그러나 왜 내가 사는 곳의 위도와 경도를 알지 못하기 때문에 이유를 이해할 수 없습니다. .. 나는 무언가를 발견했으며 작동하지만 주소 목록으로 변환됩니다. 나는 가능한 한 쉽게 뭔가를 원한다. 당신을 감사하고 좋은 하루문자열을 위도와 경도로 변환
package com.currencymeeting.activities;
import java.io.IOException;
import java.util.List;
import android.location.Address;
import android.location.Geocoder;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.widget.Toast;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
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 GoogleMapsActivity extends FragmentActivity{
GoogleMap googleMap;
MarkerOptions markerOptions;
LatLng latLng;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_google_maps);
SupportMapFragment supportMapFragment = (SupportMapFragment)
getSupportFragmentManager().findFragmentById(R.id.googleMap);
googleMap = supportMapFragment.getMap();
new GeocoderTask().execute("USA New York");
}
private class GeocoderTask extends AsyncTask<String, Void, List<Address>>{
@Override
protected List<Address> doInBackground(String... locationName) {
// Creating an instance of Geocoder class
Geocoder geocoder = new Geocoder(getBaseContext());
List<Address> addresses = null;
try {
// Getting a maximum of 3 Address that matches the input text
addresses = geocoder.getFromLocationName(locationName[0], 1);
} catch (IOException e) {
e.printStackTrace();
}
return addresses;
}
@Override
protected void onPostExecute(List<Address> addresses) {
if(addresses==null || addresses.size()==0){
Toast.makeText(getBaseContext(), "No Location found", Toast.LENGTH_SHORT).show();
}
// Clears all the existing markers on the map
googleMap.clear();
// Adding Markers on Google Map for each matching address
for(int i=0;i<addresses.size();i++){
Address address = (Address) addresses.get(i);
// Creating an instance of GeoPoint, to display in Google Map
latLng = new LatLng(address.getLatitude(), address.getLongitude());
String addressText = String.format("%s, %s",
address.getMaxAddressLineIndex() > 0 ? address.getAddressLine(0) : "",
address.getCountryName());
markerOptions = new MarkerOptions();
markerOptions.position(latLng);
markerOptions.title(addressText);
googleMap.addMarker(markerOptions);
// Locate the first location
if(i==0)
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng,16));
}
}
}
}
기본적으로, 우리는 당신 자신의 목적을 위해 다른 사람의 코드를 편집하기를 원하십니까? – HavelTheGreat
@ 엘리 손 (Elizion)이 암시하고있는 것처럼, 이것은 당신이 원하는 것을하기 위해 많은 수정을해서는 안되며, 튜토리얼을 복사하지 않고 많은 것을 시도한 것처럼 보입니다. – zgc7009
오 세상에 .. 나는 그것을 수정했다 .. 목록에서 아닌 문자열에서 주소를 만들고 싶다.> ... 나는 그 주석을 지우면 더 잘 벌리고있다 ...? – Mike