我是Google Maps API v2的新手,想要整合通过此基本链接提供的地图:https://tiles.guildwars2.com/{continent_id}/{floor}/{zoom}/{x}/{y}.jpg。我的问题是,一切都好,但让我们开始使用以下内容:
1)如何设置任何一侧没有灰色空间的地图大小? 2)如何正确移动地图,因为我显然有4个参数,而我可以使用getTileUrl一次只更改3个参数? 3)为什么瓷砖混合而且没有以正确的顺序显示?
地图文档可在此处获得: http://wiki.guildwars2.com/wiki/API:2/maps http://wiki.guildwars2.com/wiki/API:Maps
工作示例链接:0.jpg
我目前的代码是:
import android.content.Intent;
import android.content.res.Configuration;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.support.design.widget.NavigationView;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.*;
import java.net.MalformedURLException;
import java.net.URL;
public class mapsContainer extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener, OnMapReadyCallback {
SupportMapFragment mapFragment;
private DrawerLayout drawer;
private Toolbar toolbar;
private ActionBarDrawerToggle toggle;
private NavigationView navigationView;
private GoogleMap mMap;
private TileOverlay mSelectedTileOverlay;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mapFragment = SupportMapFragment.newInstance();
setContentView(R.layout.activity_maps_container);
toolbar = (Toolbar) findViewById(R.id.toolbar);
drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
navigationView = (NavigationView) findViewById(R.id.nav_view);
setSupportActionBar(toolbar);
toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close) {
/**
* Called when a drawer has settled in a completely closed state.
*/
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
/**
* Called when a drawer has settled in a completely open state.
*/
public void onDrawerOpened(View drawerView) {
super.onDrawerOpened(drawerView);
invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
}
};
drawer.addDrawerListener(toggle);
navigationView.setNavigationItemSelectedListener(this);
ConnectivityManager connMgr = (ConnectivityManager) this.getSystemService(CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
View navHeader = navigationView.getHeaderView(0);
if (networkInfo != null && networkInfo.isConnected()) {
TextView connectionStatus = (TextView) navHeader.findViewById(R.id.connection_status);
connectionStatus.setText(R.string.common_online);
} else {
TextView connectionStatus = (TextView) navHeader.findViewById(R.id.connection_status);
connectionStatus.setText(R.string.common_offline);
}
toggle.syncState();
FragmentManager fm = getSupportFragmentManager();
fm.beginTransaction().replace(R.id.mapsFragement, mapFragment).commit();
mapFragment.getMapAsync(this);
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
toggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
toggle.onConfigurationChanged(newConfig);
}
@Override
public void onBackPressed() {
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
// If the nav drawer is open, hide action items related to the content view
boolean drawerOpen = drawer.isDrawerOpen(GravityCompat.START);
return super.onPrepareOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.syncProfile) {
//String res = gwApiAccess.apiQueryAuthorized("https://api.guildwars2.com/v2/account/dyes");
//Log.d(DEBUG_TAG,"res: " + res);
}
return super.onOptionsItemSelected(item);
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.nav_home) {
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
} else if (id == R.id.nav_profile) {
Intent intent = new Intent(this, profile.class);
startActivity(intent);
} else if (id == R.id.nav_itemDB) {
Intent intent = new Intent(this, items.class);
startActivity(intent);
} else if (id == R.id.nav_guilds) {
Intent intent = new Intent(this, guilds.class);
startActivity(intent);
} else if (id == R.id.nav_maps) {
//Do nothing
} else if (id == R.id.settings) {
Intent intent = new Intent(this, SettingsActivity.class);
startActivity(intent);
}
drawer.closeDrawer(GravityCompat.START);
return true;
}
@Override
protected void onStop() {
super.onStop();
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.setMapType(GoogleMap.MAP_TYPE_NONE);
CustomUrlTileProvider mTileProvider = new CustomUrlTileProvider(256, 256, "https://tiles.guildwars2.com/{continent_id}/{floor}/{zoom}/{x}/{y}.jpg");
mSelectedTileOverlay = mMap.addTileOverlay(new TileOverlayOptions().tileProvider(mTileProvider).zIndex(-1));
mMap.getUiSettings().setTiltGesturesEnabled(false);
mMap.getUiSettings().setRotateGesturesEnabled(false);
}
private static class CustomUrlTileProvider extends UrlTileProvider {
private String baseUrl;
CustomUrlTileProvider(int width, int height, String url) {
super(width, height);
this.baseUrl = url;
}
@Override
public URL getTileUrl(int zoom, int x, int y) {
try {
return new URL(baseUrl.replace("{continent_id}", "" + 1).replace("{floor}", "" + 0).replace("{zoom}", "" + zoom).replace("{x}", "" + x).replace("{y}", "" + y));
} catch (MalformedURLException e) {
e.printStackTrace();
}
return null;
}
private boolean checkTileExists(int x, int y, int zoom) {
int minZoom = 0;
int maxZoom = 0;
return !(zoom < minZoom || zoom > maxZoom);
}
}
}
答案 0 :(得分:0)
好的,因为学校因为学校的休息,我发现了除了第一件事以外的一切。
我对错误的瓷砖的错误是我没有正确的参数顺序。
另外还有很多参数,我会在不久的将来为自己设计一个解决方法。
所以我会在粉碎显示器之前关闭线程并打开一个新线程,因为某些东西不起作用。