0
當ia'm構建我的應用我只是想顯示的地圖與我的位置我可以在Android開發中使用任何類型的地圖,除了谷歌地圖嗎?
我codded它,但它需要我一個良好的互聯網連接,以顯示或將崩潰我所有的應用程序..
我該如何處理這個問題
是否有任何一種地圖我可以在我的編程中使用除了谷歌地圖?
或任何代碼技巧?
這裏是我的代碼:
package com.gideon.address;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import android.app.ProgressDialog;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.Handler;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.GoogleMap.OnMyLocationButtonClickListener;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class map extends android.support.v4.app.FragmentActivity {
private GoogleMap mMap;
private double mlat;
private double mlon;
LocationManager locationManager;
LocationListener locationListener;
// All static variables
static final String URL = "http://procode.co/app_ss/search.php?lat=222&lng=656.111&radius=3200000";
// XML node keys
static final String KEY_MARKER = "marker"; // parent node
static final String KEY_LAT = "lat";
static final String KEY_LNG = "lng";
XMLParser parser = new XMLParser();
String xml = parser.getXmlFromUrl(URL); // getting XML
Document doc = parser.getDomElement(xml); // getting DOM element
NodeList nl = doc.getElementsByTagName(KEY_MARKER);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
final ProgressDialog dialog = ProgressDialog.show(map.this, "",
"Loading..Wait..", true);
dialog.show();
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
// your code here
setUpMapIfNeeded();
dialog.dismiss();
}
}, 10000);
}
@Override
protected void onResume() {
super.onResume();
setUpMapIfNeeded();
}
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the
// map.
// if (mMap == null) {
// Try to obtain the map from the SupportMapFragment.
mMap = ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map)).getMap();
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
// Check if we were successful in obtaining the map.
// if (mMap != null) {
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(
26.0000, 30.0000), 6));
mMap.setMyLocationEnabled(true);
mMap.setOnMyLocationButtonClickListener(new OnMyLocationButtonClickListener() {
public boolean onMyLocationButtonClick() {
locationManager = (LocationManager) map.this
.getSystemService(Context.LOCATION_SERVICE);
// Define a listener that responds to location updates
locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
// Called when a new location is found by the
// network location provider.
mlat = location.getLatitude();
mlon = location.getLongitude();
mMap.setMyLocationEnabled(true);
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(
new LatLng(mlat, mlon), 12));
MarkerOptions marker = new MarkerOptions().position(
new LatLng(mlat, mlon)).title("My Location");
// Changing marker icon
marker.icon(BitmapDescriptorFactory
.defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
// adding marker
mMap.addMarker(marker);
// looping through all item nodes <item>
for (int i = 0; i < nl.getLength(); i++) {
Element e = (Element) nl.item(i);
double x = Double.parseDouble(parser.getValue(e,
KEY_LAT));
double y = Double.parseDouble(parser.getValue(e,
KEY_LNG));
mMap.addMarker(new MarkerOptions().title("สอัิ")
.position(new LatLng(x, y)));
}
locationManager.removeUpdates(locationListener);
}
public void onStatusChanged(String provider, int status,
Bundle extras) {
}
public void onProviderEnabled(String provider) {
}
public void onProviderDisabled(String provider) {
}
};
// Register the listener with the Location Manager to
// receive location updates
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER, 0, 0,
locationListener);
return true;
}
});
// }
// }
}
}