gpt4 book ai didi

android - Android 中的谷歌地图方向

转载 作者:搜寻专家 更新时间:2023-11-01 09:48:23 25 4
gpt4 key购买 nike

我正在尝试在我的项目中使用 Google map 方向

此处引用:http://www.akexorcist.com/2015/12/google-direction-library-for-android-en.html

但它给了我这个错误 -> The number of method references in a .dex file cannot exceed 64K

我的代码

public class Confirmation extends AppCompatActivity implements OnMapReadyCallback,DirectionCallback {

double locationLatMap;
double locationLongMap;
double destinationLatMap;
double destinationLongMap;


LatLng locationAPI=new LatLng(locationLatMap,locationLongMap);
LatLng DestinationAPI=new LatLng(destinationLatMap,destinationLongMap);

private GoogleMap mMap;
String serverKey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx";

Location location=new Location("location");
Location destination=new Location("destination");

String start,end;
String cost;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.confirmation_act);


SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
//

EditText lat1=(EditText)findViewById(R.id.lat1);
EditText lat2=(EditText)findViewById(R.id.lat2);


Bundle bundle = getIntent().getExtras();
final Double d1=bundle.getDouble("d1");
final Double d2=bundle.getDouble("d2");
final Double d3=bundle.getDouble("d3");
final Double d4=bundle.getDouble("d4");

locationLatMap=d1;
locationLongMap=d2;
destinationLatMap=d3;
destinationLongMap=d4;


Geocoder geocoder = new Geocoder(this, Locale.getDefault());
List<Address> addresses = null;
try {
addresses = geocoder.getFromLocation(d1, d2, 1);
String cityName = addresses.get(0).getAddressLine(0);
String stateName = addresses.get(0).getAddressLine(1);
String countryName = addresses.get(0).getAddressLine(2);

lat1.setText("From: "+"\n"+cityName + " " + stateName + " " + countryName);

start=cityName + " " + stateName + " " + countryName;

} catch (IOException e) {
e.printStackTrace();
}


Geocoder geocoder1 = new Geocoder(this, Locale.getDefault());
List<Address> addresses1 = null;
try {
addresses1 = geocoder1.getFromLocation(d3, d4, 1);
String cityName = addresses1.get(0).getAddressLine(0);
String stateName = addresses1.get(0).getAddressLine(1);
String countryName = addresses1.get(0).getAddressLine(2);

lat2.setText("To: "+"\n"+cityName + " " + stateName + " " + countryName);
end=cityName + " " + stateName + " " + countryName;
} catch (IOException e) {
e.printStackTrace();
}

Button fareEstimate_confirm= (Button) findViewById(R.id.fareEstimate_Confirm);

fareEstimate_confirm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

location.setLatitude(d1);
location.setLongitude(d2);
destination.setLatitude(d3);
destination.setLongitude(d4);

double distance = location.distanceTo(destination);

double base = 3;
double calc = base * distance;
NumberFormat nf = NumberFormat.getInstance(); // get instance
nf.setMaximumFractionDigits(2); // set decimal places
String s = nf.format(calc);
try {
TextView tv = (TextView) findViewById(R.id.price_confirm_tv);
tv.setText("Cost :"+"\n"+s.charAt(0)+ s.charAt(1) +s.charAt(2)+s.charAt(3)+s.charAt(4)+" EGP");
cost=tv.getText().toString();
}catch (Exception e){

}
}
});
}

public void confirmBtn_m (View view)
{
// Calculate Date&Time
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd\nHH:mm");
String currentDateandTime = sdf.format(new Date());

// Calculate Cost
location.setLatitude(locationLatMap);
location.setLongitude(locationLongMap);
destination.setLatitude(destinationLatMap);
destination.setLongitude(destinationLongMap);

double distance = location.distanceTo(destination);

double base = 2;
double calc = base * distance;
NumberFormat nf = NumberFormat.getInstance(); // get instance
nf.setMaximumFractionDigits(2); // set decimal places
String s = nf.format(calc);

try {
cost=s.charAt(0) + "" + s.charAt(1) +" EGP";
}catch (Exception e){

}

// Creating New Trip
ParseGeoPoint location=new ParseGeoPoint(locationLatMap,locationLongMap);

final ParseObject trip= new ParseObject("Trip");

trip.put("source",start);
trip.put("destinations",end);
trip.put("cost",cost);
trip.put("date",currentDateandTime);
trip.put("status","Requesting");
trip.put("location",location);
//trip.put("sLat",locationLatMap);
//trip.put("sLong",locationLongMap);
trip.put("eLat",destinationLatMap);
trip.put("eLong",destinationLongMap);


ParseRelation<ParseUser> tripUser=trip.getRelation("user");
tripUser.add(ParseUser.getCurrentUser());


trip.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
if (e==null)
{
Toast.makeText(Confirmation.this, "Request Successful !!\n Wait To Response ", Toast.LENGTH_SHORT).show();
Intent intent=new Intent(Confirmation.this,Requesting.class);

Bundle bundle = new Bundle();
bundle.putString("objectId",trip.getObjectId());
bundle.putDouble("d1",locationLatMap);
bundle.putDouble("d2",locationLongMap);
intent.putExtras(bundle);

startActivity(intent);
}
else {
Toast.makeText(Confirmation.this, "Requesting Failed !!", Toast.LENGTH_SHORT).show();
}
}
});
}


@Override
public void onMapReady(GoogleMap googleMap) {


requestDirection();
}

public void requestDirection() {

GoogleDirection.withServerKey(serverKey)
.from(locationAPI)
.to(DestinationAPI)
.transportMode(TransportMode.DRIVING)
.execute(this);
}


@Override
public void onDirectionSuccess(Direction direction, String rawBody) {
mMap.addMarker(new MarkerOptions().position(locationAPI));
mMap.addMarker(new MarkerOptions().position(DestinationAPI));


ArrayList<LatLng> directionPositionList = direction.getRouteList().get(0).getLegList().get(0).getDirectionPoint();
mMap.addPolyline(DirectionConverter.createPolyline(this, directionPositionList, 5, Color.DKGRAY));

}

@Override
public void onDirectionFailure(Throwable t) {

}
}

最佳答案

出现此错误是因为您的应用程序超过了 65k 方法的限制。要解决这个问题,您必须启用 multidex 支持。创建一个应用类如下,并在manifest.xml中注册到appliation标签下。

public class YouApplication extends Application {

@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}

}

更新你的build.gradle文件

 android {
compileSdkVersion 22
buildToolsVersion "23.0.0"

defaultConfig {
minSdkVersion 14 //lower than 14 doesn't support multidex
targetSdkVersion 22

// Enabling multidex support.
multiDexEnabled true
}
}

dependencies {
compile 'com.android.support:multidex:1.0.1'
}

Android官方文档Building Apps with Over 64K Methods

关于android - Android 中的谷歌地图方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36848289/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com