나는 내가 다음 코드를 작성했습니다 그것을 위해, 안드로이드 프로그램에서 두 도시 사이의 주행 거리를 표시 할 :안드로이드에서 밀집 계산?
package com.example.distancebcities;
import java.io.IOException;
import java.util.List;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView;
import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
public class MainActivity extends MapActivity {
//extending the MapActivity here
Geocoder geocoder = null;
MapView mapView = null;
@Override
//location display
protected boolean isLocationDisplayed() {
return false;
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mapView = (MapView) findViewById(R.id.geoMap);
mapView.setBuiltInZoomControls(true);
// lat/long of Jacksonville, FL
int lat = (int) (30.334954 * 1000000);
int lng = (int) (-81.5625 * 1000000);
GeoPoint pt = new GeoPoint(lat, lng);
mapView.getController().setZoom(10);
mapView.getController().setCenter(pt);
geocoder = new Geocoder(this);
}
public void doClick(View arg0) {
try {
EditText loc = (EditText) findViewById(R.id.location);
//getting the dittext id
String locationName = loc.getText().toString();
List<Address> addressList = geocoder.getFromLocationName(locationName, 5);
if (addressList != null && addressList.size() > 0) {
int lat = (int) (addressList.get(0).getLatitude() * 1000000);
int lng = (int) (addressList.get(0).getLongitude() * 1000000);
//getting the lat and long postions of the cities
GeoPoint pt = new GeoPoint(lat, lng);
mapView.getController().setZoom(15);
mapView.getController().setCenter(pt);
//zooming and display the place of the edit text entered value .
}
catch (IOException e){
e.printStackTrace();
}
}
}
나는 장소를 얻고 있지만 지금은 두 도시 사이의 거리를 표시합니다.
이 프로그램을 어떻게 진행할 수 있습니까? 아니면이를 수행 할 수있는 다른 방법이 있습니까? 앞으로 나아갈 수 있도록 유용한 링크를 보내주십시오.
프로그램? – user1787493
이것은 방법입니다. 당신은 단지 시작 및 끝 위치를 전달해야합니다, 그것은 두 위치 사이의 거리 (미터)를 반환합니다. 당신은 어디든 둘 수 있습니다 –
프로그래밍을 배울 수 없다, 그냥 당신을 도울 수 있습니다 .. –