Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 除了谷歌地图,我可以在android开发中使用任何类型的地图吗?_Java_Android_Google Maps_Import_Geolocation - Fatal编程技术网

Java 除了谷歌地图,我可以在android开发中使用任何类型的地图吗?

Java 除了谷歌地图,我可以在android开发中使用任何类型的地图吗?,java,android,google-maps,import,geolocation,Java,Android,Google Maps,Import,Geolocation,当我构建我的应用程序时,我只想显示一张带有我位置的地图 我编写了它,但它需要我有一个良好的互联网连接才能显示,否则它将使我的所有应用程序崩溃 我如何处理这个问题 除了谷歌地图之外,还有什么地图可以在我的编程中使用吗??? 或者任何代码技巧 这是我的密码: package com.gideon.address; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; im

当我构建我的应用程序时,我只想显示一张带有我位置的地图

我编写了它,但它需要我有一个良好的互联网连接才能显示,否则它将使我的所有应用程序崩溃

我如何处理这个问题

除了谷歌地图之外,还有什么地图可以在我的编程中使用吗??? 或者任何代码技巧

这是我的密码:

    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;
            }
        });

        // }
        // }
    }

}

作为谷歌地图的替代方案,请看一看MapQuest