简体   繁体   English

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

[英]can i use any kind of maps in android development except google maps?

when ia'm building my app i just wanna to display a map with my location 当我在建立我的应用程式时,我只想显示我所在位置的地图

i codded it , but it required me a good internet connection to display or it will crash my all app .. 我对它进行了编码,但需要我良好的互联网连接才能显示,否则它将使我的所有应用程序崩溃..

how can i deal with this issue 我该如何处理这个问题

is there is any kind of maps can i use in my programming except google maps ??? 除了谷歌地图,我可以在编程中使用哪种地图?
or any code tricks ?? 或任何代码技巧?

here is my code : 这是我的代码:

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

        // }
        // }
    }

}

As an alternative to Google Maps, have a look at MapQuest. 作为Google Maps的替代品,请查看MapQuest。

http://developer.mapquest.com/web/products/featured/android-maps-api http://developer.mapquest.com/web/products/featured/android-maps-api

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM