如何通过shop_name获取经度和经度并将其显示在地图上?

时间:2012-10-02 19:18:43

标签: android android-mapview

我试图通过我的数据库中的shop_name获取经度和纬度,以便我可以使用它从我的位置获取方向。

这是我的地图活动:

public class SearchLocation extends MapActivity {
private MapView mapView;
private LocationManager locManager;
private LocationListener locListener;

location_dao location_dao = new location_dao();

String shopname = "0", address = "0", phone_number = "0";

public CharSequence lat = "0", lng = "0", lat2 = "0", lng2 = "0";

LocationManager mlocManager;
LocationListener mlocListener;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.map_shoprepair);

    final ActionBar actionBar = (ActionBar) findViewById(R.id.actionbar);
    actionBar.setTitle(getString(R.string.app_name));

    actionBar.setHomeAction(new IntentAction(this, new Intent(this,
            Home_Activity.class), R.drawable.home));

    initMap();
    initLocationManager();
}

private void initMap() {
    mapView = (MapView) findViewById(R.id.map_view);
    mapView.setBuiltInZoomControls(true);
    mapView.displayZoomControls(true);
    mapView.getController().setZoom(15);
    mapView.setSatellite(false);

}

private void initLocationManager() {
    locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    locListener = new LocationListener() {
        //method ini akan dijalankan apabila koordinat GPS berubah
        public void onLocationChanged(Location newLocation) {
            tampilkanPosisikeMap(newLocation);
        }

        public void onProviderDisabled(String arg0) {
        }

        public void onProviderEnabled(String arg0) {
        }

        public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
        }
    };
    locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
            locListener);

}

protected void tampilkanPosisikeMap(Location newLocation) {
    List overlays = mapView.getOverlays();

    // first remove old overlay
    if (overlays.size() > 0) {
        for (Iterator iterator = overlays.iterator(); iterator.hasNext();) {
            iterator.next();
            iterator.remove();
        }
    }

    // transform the location to a geopoint
    GeoPoint geopoint = new GeoPoint(
    (int) (newLocation.getLatitude() * 1E6), (int) (newLocation.getLongitude() * 1E6));

    // initialize icon
    Drawable icon = getResources().getDrawable(R.drawable.marker1);
    icon.setBounds(0, 0, icon.getIntrinsicWidth(), icon.getIntrinsicHeight());

    // create my overlay and show it
    mapsOverlay overlay = new mapsOverlay(icon);
    OverlayItem item = new OverlayItem(geopoint, "My Location", null);
    overlay.addItem(item);
    mapView.getOverlays().add(overlay);

    // move to location
    mapView.getController().animateTo(geopoint);

    // redraw map
    mapView.postInvalidate();
}



public class MyLocationListener implements LocationListener {
    @Override
    public void onLocationChanged(final Location loc) {
        SearchLocation.this.parsingGetServerLocationData(shopname);

        if (lat != "0" && lng != "0") {
            loc.getLatitude();

            loc.getLongitude();

            mlocManager.removeUpdates(this);
            lat2 = String.valueOf(loc.getLatitude());
            lng2 = String.valueOf(loc.getLongitude());

            Location bLocation = new Location("reverseGeocoded");
            bLocation.setLatitude(Double.parseDouble((String) lat2));
            bLocation.setLongitude(Double.parseDouble((String) lng2));
            Location aLocation = new Location("reverseGeocoded");
            aLocation.setLatitude(Double.parseDouble((String) lat));
            aLocation.setLongitude(Double.parseDouble((String) lng));

            Location myLocation = LocationHelper
                    .getLastLocation(getBaseContext());

            int distance = (int) aLocation.distanceTo(bLocation);

            // handler.sendEmptyMessage(0);

            // Toast.makeText(searchLocation.this, "Your distance: " +
            // distance + " Meter", Toast.LENGTH_SHORT).show();

            Uri uri = Uri.parse("http://maps.google.com/maps?f=d&saddr="
                    + myLocation.getLatitude() + "%20"
                    + myLocation.getLongitude() + "&daddr=" + lat + "%20"
                    + lng + "&hl=en");
            Intent it = new Intent(Intent.ACTION_VIEW, uri);

            startActivity(it);
            lat = "0";
            lng = "0";
        } else {
            // handler.sendEmptyMessage(0);
            // Toast.makeText(searchLocation.this, "no data found",
            // Toast.LENGTH_LONG).show();
        }
    }

    public void onProviderDisabled(String provider) {
        Toast.makeText(getApplicationContext(),
                "Gps Disabled, Switch to Network", Toast.LENGTH_SHORT)
                .show();
    }

    @Override
    public void onProviderEnabled(String provider) {
        Toast.makeText(getApplicationContext(), "Gps Enabled",
                Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
    }
}

public void parsingGetServerLocationData(String shop_name) {
    try {
        JSONArray jArray = new JSONArray(
                location_dao.getServerLocationData(shop_name));
        for (int i = 0; i < jArray.length(); i++) {
            JSONObject json_data = jArray.getJSONObject(i);
            // Get an output to the screen
            shopname = json_data.getString("SHOP_NAME");
            lat = json_data.getString("LATITUDE");
            lng = json_data.getString("LONGITUDE");

            Log.e("log_tag",
                    "parsingGetServerLocationData" + shopname.toString());
        }

    } catch (JSONException e) {
        // TODO: handle exception
        Log.e("log_tag", "Error parsing data " + e.toString());
        shopname = "0";
        lat = "0";
        lng = "0";
    }

}

public void parsingGetServerDetailLocationData(String shop_name)
{
    try{
           JSONArray jArray = new JSONArray(location_dao.getServerDetailLocationData(shop_name));
           for(int i=0;i<jArray.length();i++){
               JSONObject json_data = jArray.getJSONObject(i);
               //Get an output to the screen                   
               shopname = json_data.getString("SHOP_NAME");
               address = json_data.getString("ADDRESS");
               phone_number = json_data.getString("PHONE_NUMBER");

               Log.e("log_tag", "parsingGetServerDetailLocationData: "+shopname.toString());
           }
       }catch(JSONException e){
           Log.e("log_tag", "Error parsing data "+e.toString());
           shopname = "0";
           address = "0";
           phone_number = "0";
       }
}

@Override
protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub
    return false;
}}

这是我调用地图活动的代码:

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    // TODO Auto-generated method stub
    final Entity_BikeShopRepair toko = adapterShop.getItem(position);

    CharSequence[] items = { "View on Map", "Call Shop" };

    AlertDialog.Builder builder = new AlertDialog.Builder(
            Tab_Shop_Repair_ListView_Activity.this);
    builder.setTitle(toko.getShop_Name());
    builder.setItems(items, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int item) {
            switch (item) {
            case 0:
                String nama = toko.getShop_Name().toString();

                Intent intentmap = new Intent(
                        Tab_Shop_Repair_ListView_Activity.this,
                        SearchLocation.class);
                startActivity(intentmap);
                break;
            case 1:
                String number = "tel:" + toko.getPhone_Number().toString();

                Intent intent = new Intent(Intent.ACTION_CALL, Uri
                        .parse(number));
                startActivity(intent);

                break;
            case 2:
                break;
            }
        }
    });
    AlertDialog alert = builder.create();
    alert.show();
}

enter image description here

这是我的logcat:

  

10-02 22:40:32.859:E / AndroidRuntime(4375):android.view.WindowManager $ BadTokenException:无法添加窗口 - 令牌android.os.BinderProxy@405139f0无效;你的活动在运行吗?   10-02 22:40:32.859:E / AndroidRuntime(4375):在android.view.ViewRoot.setView(ViewRoot.java:532)   10-02 22:40:32.859:E / AndroidRuntime(4375):在android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)   10-02 22:40:32.859:E / AndroidRuntime(4375):在android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)   10-02 22:40:32.859:E / AndroidRuntime(4375):在android.view.Window $ LocalWindowManager.addView(Window.java:424)   10-02 22:40:32.859:E / AndroidRuntime(4375):在android.app.Dialog.show(Dialog.java:241)   10-02 22:40:32.859:E / AndroidRuntime(4375):at com.wilis.hellotabwidget.Tab_Shop_Repair_ListView_Activity $ 1.gotResult(Tab_Shop_Repair_ListView_Activity.java:75)   10-02 22:40:32.859:E / AndroidRuntime(4375):at com.wilis.dao.bike_shop_dao $ 1.gotResult(bike_shop_dao.java:84)   10-02 22:40:32.859:E / AndroidRuntime(4375):at com.wilis.connections.ConnectionHandler.handleMessage(ConnectionHandler.java:68)   10-02 22:40:32.859:E / AndroidRuntime(4375):在android.os.Handler.dispatchMessage(Handler.java:99)   10-02 22:40:32.859:E / AndroidRuntime(4375):在android.os.Looper.loop(Looper.java:130)   10-02 22:40:32.859:E / AndroidRuntime(4375):在android.app.ActivityThread.main(ActivityThread.java:3687)   10-02 22:40:32.859:E / AndroidRuntime(4375):at java.lang.reflect.Method.invokeNative(Native Method)   10-02 22:40:32.859:E / AndroidRuntime(4375):at java.lang.reflect.Method.invoke(Method.java:507)   10-02 22:40:32.859:E / AndroidRuntime(4375):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:867)   10-02 22:40:32.859:E / AndroidRuntime(4375):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)   10-02 22:40:32.859:E / AndroidRuntime(4375):at dalvik.system.NativeStart.main(Native Method)   10-02 22:41:44.609:E / HttpResponse(4493):{&#34;结果&#34;:1,&#34;数据&#34;:[{&#34; 0&#34;:&# 34; Toko Sepeda Alam Baru&#34;,&#34; shop_name&#34;:&#34; Toko Sepeda Alam Baru&#34;,&#34; 1&#34;:&#34; Jl。 Malioboro No. 151&#34;,&#34;地址&#34;:&#34; Jl。 Malioboro No. 151&#34;,&#34; 2&#34;:&#34; 0274514903&#34;,&#34; phone_number&#34;:&#34; 0274514903&#34;},{&#34; 0&#34;:&#34; Toko Sepeda Tri Jaya&#34;,&#34; shop_name&#34;:&#34; Toko Sepeda Tri Jaya&#34;,&#34; 1&#34;:&#34 ; JL。 Bridjend。 Katamso 210 -212&#34;,&#34;地址&#34;:&#34; Jl。 Bridjend。 Katamso 210 -212&#34;,&#34; 2&#34;:&#34; 0274375180&#34;,&#34; phone_number&#34;:&#34; 0274375180&#34;},{&#34; 0&#34;:&#34; Sinar Makmur&#34;,&#34; shop_name&#34;:&#34; Sinar Makmur&#34;,&#34; 1&#34;:&#34; Jl。 Brigjen Katamso 92B&#34;,&#34;地址&#34;:&#34; Jl。 Brigjen Katamso 92B&#34;,&#34; 2&#34;:&#34; 0274378352&#34;,&#34; phone_number&#34;:&#34; 0274378352&#34;},{&#34; 0& #34;:&#34; Orion&#34;,&#34; shop_name&#34;:&#34; Orion&#34;,&#34; 1&#34;:&#34; Jl Brigjen Katamso 56&#34 ;,&#34;地址&#34;:&#34; Jl Brigjen Katamso 56&#34;,&#34; 2&#34;:&#34; 0274374986&#34;,&#34; phone_number&#34;: &#34; 0274374986&#34;},{&#34; 0&#34;:&#34; Pasar Sepeda PPSY&#34;,&#34; shop_name&#34;:&#34; Pasar Sepeda PPSY&#34; &#34; 1&#34;:&#34; JL。 Menteri Supeno,Sorosutan&#34;,&#34;地址&#34;:&#34; Jl。 Menteri Supeno,Sorosutan&#34;&#34; 2&#34;:&#34; - &#34;,&#34; phone_number&#34;:&#34; - &#34;},{&# 34; 0&#34;:&#34; Toko Sepeda Adi Mitra&#34;,&#34; shop_name&#34;:&#34; Toko Sepeda Adi Mitra&#34;,&#34; 1&#34;:& #34; JL。 Mayjen Sutoyo 09&#34;,&#34;地址&#34;:&#34; Jl。 Mayjen Sutoyo 09&#34;,&#34; 2&#34;:&#34; 0274375199&#34;,&#34; phone_number&#34;:&#34; 0274375199&#34;},{&#34; 0& #34;:&#34; Pasar Sepeda GAPPSTA&#34;,&#34; shop_name&#34;:&#34; Pasar Sepeda GAPPSTA&#34;,&#34; 1&#34;:&#34; Jl。公吨。 Haryono&#34;&#34;地址&#34;:&#34; JL。公吨。 Haryono&#34;&#34; 2&#34;:&#34; - &#34;&#34; PHONE_NUMBER&#34;:&#34; - &#34;},{&#34; 0& #34;:&#34; Pasar Sepeda Terban&#34;,&#34; shop_name&#34;:&#34; Pasar Sepeda Terban&#34;,&#34; 1&#34;:&#34; Jl。 C. Simanjuntak&#34;,&#34;地址&#34;:&#34; Jl。 C. Simanjuntak&#34;,&#34; 2&#34;:&#34; - &#34;,&#34; phone_number&#34;:&#34; - &#34;},{&#34 ; 0&#34;:&#34; Toko Sepeda Marcopolo&#34;,&#34; shop_name&#34;:&#34; Toko Sepeda Marcopolo&#34;,&#34; 1&#34;:&#34; JL。 Sosrowijayan No. 11&#34;,&#34;地址&#34;:&#34; Jl。 Sosrowijayan No. 11&#34;,&#34; 2&#34;:&#34; 0274587636&#34;,&#34; phone_number&#34;:&#34; 0274587636&#34;},{&#34; 0&#34;:&#34; Toko Sepeda Esa Jaya&#34;,&#34; shop_name&#34;:&#34; Toko Sepeda Esa Jaya&#34;,&#34; 1&#34;:&#34 ; JL。 KHA。 Dahlan No 72&#34;,&#34;地址&#34;:&#34; Jl。 KHA。 Dahlan No 72&#34;,&#34; 2&#34;:&#34; 0274515605&#34;,&#34; phone_number&#34;:&#34; 0274515605&#34;},{&#34; 0& #34;:&#34; Toko Sepeda United&#34;,&#34; shop_name&#34;:&#34; Toko Sepeda United&#34;,&#34; 1&#34;:&#34; Jl。 P. Diponegoro 42&#34;,&#34;地址&#34;:&#34; Jl。 P. Diponegoro 42&#34;,&#34; 2&#34;:&#34; 0274518375&#34;,&#34; phone_number&#34;:&#34; 0274518375&#34;},{&#34; 0&#34;:&#34; Toko Sepeda Taman Sari Indah&#34;,&#34; shop_name&#34;:&#34; Toko Sepeda Taman Sari Indah&#34;,&#34; 1&#34;:& #34; Jl.Wachid Hasyim 129&#34;,&#34;地址&#34;:&#34; Jl.Wachid Hasyim 129&#34;,&#34; 2&#34;:&#34; - &# 34;,&#34; phone_number&#34;:&#34; - &#34;},{&#34; 0&#34;:&#34; Toko Sepeda Salam&#34;,&#34; shop_name&# 34;:&#34; Toko Sepeda Salam&#34;,&#34; 1&#34;:&#34; Jl.Wachid Hasyim 19&#34;,&#34;地址&#34;:&#34; Jl .Wachid Hasyim 19&#34;,&#34; 2&#34;:&#34; 0274374913&#34;,&#34; phone_number&#34;:&#34; 0274374913&#34;},{&#34; 0&#34;:&#34; AB Bike&#34;,&#34; shop_name&#34;:&#34; AB Bike&#34;,&#34; 1&#34;:&#34; Jl。 HOS Cokroaminoto No.45&#34;,&#34;地址&#34;:&#34; Jl。 HOS Cokroaminoto No.45&#34;,&#34; 2&#34;:&#34; 0274618027&#34;,&#34; phone_number&#34;:&#34; 0274618027&#34;},{&#34 ; 0&#34;:&#34; Indo Jaya Sakti&#34;,&#34; shop_name&#34;:&#34; Indo Jaya Sakti&#34;,&#34; 1&#34;:&#34; JL。 Hos Cokroaminoto No. 157 B&#34;,&#34;地址&#34;:&#34; Jl。 Hos Cokroaminoto No. 157 B&#34;,&#34; 2&#34;:&#34; 0274620188&#34;,&#34; phone_number&#34;:&#34; 0274620188&#34;},{&# 34; 0&#34;:&#34; Toko Sepeda Rodalink&#34;,&#34; shop_name&#34;:&#34; Toko Sepeda Rodalink&#34;,&#34; 1&#34;:&#34 ; JL。 Laskda Adisucipto Km 6 No. 155C&#34;,&#34;地址&#34;:&#34; Jl。 Laskda Adisucipto Km 6 No. 155C&#34;,&#34; 2&#34;:&#34; 0274487229&#34;,&#34; phone_number&#34;:&#34; 0274487229&#34;},{& #34; 0&#34;:&#34; Pedro Pit Shop(Pusat)&#34;,&#34; shop_name&#34;:&#34; Pedro Pit Shop(Pusat)&#34;,&#34; 1&#34;:&#34;惹。 Kebon Agung Km 4,6 Los Danon,Godean&#34;,&#34;地址&#34;:&#34; Jln。 Kebon Agung Km 4,6 Los Danon,Godean&#34;&#34; 2&#34;:&#34; 0816972823&#34;,&#34; phone_number&#34;:&#34; 0816972823&#34;} ,{&#34; 0&#34;:&#34; Pedro Pit Shop(Cabang)&#34;,&#34; shop_name&#34;:&#34; Pedro Pit Shop(Cabang)&#34;, &#34; 1&#34;:&#34; Godean Km 9,Godean&#34;,&#34;地址&#34;:&#34; Godean Km 9,Godean&#34;,&#34; 2&# 34;:&#34; 02747171665&#34;,&#34; phone_number&#34;:&#34; 02747171665&#34;},{&#34; 0&#34;:&#34; Pedro Pit Shop(Cabang) )&#34;,&#34; shop_name&#34;:&#34; Pedro Pit Shop(Cabang)&#34;,&#34; 1&#34;:&#34; Jln。 Lingkar Utara(环路),Karangnongko,Maguwo,Depok,Sleman&#34;,&#34;地址&#34;:&#34; Jln。 Lingkar Utara(环路),Karangnongko,Maguwo,Depok,Sleman&#34;,&#34; 2&#34;:&#34; 085729075277&#34;,&#34; phone_number&#34;:&#34; 085729075277&# 34;},{&#34; 0&#34;:&#34; Nurhayati Bike&#34;,&#34; shop_name&#34;:&#34; Nurhayati Bike&#34;,&#34; 1&#34 ;:&#34; Jalan Raya Cebongan Sleman&#34;,&#34;地址&#34;:&#34; Jalan Raya Cebongan Sleman&#34;,&#34; 2&#34;:&#34; - & #34;,&#34; phone_number&#34;:&#34; - &#34;},{&#34; 0&#34;:&#34;爱Sepeda&#34;,&#34; shop_name&# 34;:&#34;爱Sepeda&#34;,&#34; 1&#34;:&#34; Gandok,Gang suryo No.16,Condongcatur,Depok,Sleman&#34;,&#34;地址&#34; ;:&#34; Gandok,Gang suryo No.16,Condongcatur,Depok,Sleman&#34;,&#34; 2&#34;:&#34; 085743919166&#34;,&#34; phone_number&#34;: &#34; 085743919166&#34;}]}   10-02 22:41:50.749:D / PhoneWindow(4493):无法保存哪个视图具有焦点,因为焦点视图com.android.internal.policy.impl.PhoneWindow$DecorView@4053e818没有id。   10-02 22:41:52.549:E / ZoomButtonsController(4493):如果所有者视图未附加到窗口,则无法使变焦控制器可见。   10-02 22:41:52.609:I / MapActivity(4493):处理网络变更通知:已连接

它从我的数据库中获取所有数据,但我想在点击时只显示一个商店名称。

10-02 22:41:44.609: E/HttpResponse(4493): {"result":1,"data":[{"0":"Toko Sepeda Alam Baru","shop_name":"Toko Sepeda Alam Baru","1":"Jl. Malioboro No. 151","address":"Jl. Malioboro No. 151","2":"0274514903","phone_number":"0274514903"},{"0":"Toko Sepeda Tri Jaya","shop_name":"Toko Sepeda Tri Jaya","1":"Jl. Bridjend. Katamso 210 -212","address":"Jl. Bridjend. Katamso 210 -212","2":"0274375180","phone_number":"0274375180"},{"0":"Sinar Makmur","shop_name":"Sinar Makmur","1":"Jl. Brigjen Katamso 92B","address":"Jl. Brigjen Katamso 92B","2":"0274378352","phone_number":"0274378352"},{"0":"Orion","shop_name":"Orion","1":"Jl Brigjen Katamso 56","address":"Jl Brigjen Katamso 56","2":"0274374986","phone_number":"0274374986"},{"0":"Pasar Sepeda PPSY","shop_name":"Pasar Sepeda PPSY","1":"Jl. Menteri Supeno, Sorosutan","address":"Jl. Menteri Supeno, Sorosutan","2":"-","phone_number":"-"},{"0":"Toko Sepeda Adi Mitra","shop_name":"Toko Sepeda Adi Mitra","1":"Jl. Mayjen Sutoyo 09","address":"Jl. Mayjen Sutoyo 09","2":"0274375199","phone_number":"0274375199"},{"0":"Pasar Sepeda GAPPSTA","shop_name":"Pasar Sepeda GAPPSTA","1":"Jl. MT. Haryono","address":"Jl. MT. Haryono","2":"-","phone_number":"-"},{"0":"Pasar Sepeda Terban","shop_name":"Pasar Sepeda Terban","1":"Jl. C. Simanjuntak","address":"Jl. C. Simanjuntak","2":"-","phone_number":"-"},{"0":"Toko Sepeda Marcopolo","shop_name":"Toko Sepeda Marcopolo","1":"Jl. Sosrowijayan No. 11","address":"Jl. Sosrowijayan No. 11","2":"0274587636","phone_number":"0274587636"},{"0":"Toko Sepeda Esa Jaya","shop_name":"Toko Sepeda Esa Jaya","1":"Jl. KHA. Dahlan No 72","address":"Jl. KHA. Dahlan No 72","2":"0274515605","phone_number":"0274515605"},{"0":"Toko Sepeda United","shop_name":"Toko Sepeda United","1":"Jl. P. Diponegoro 42","address":"Jl. P. Diponegoro 42","2":"0274518375","phone_number":"0274518375"},{"0":"Toko Sepeda Taman Sari Indah","shop_name":"Toko Sepeda Taman Sari Indah","1":"Jl.Wachid Hasyim 129","address":"Jl.Wachid Hasyim 129","2":"-","phone_number":"-"},{"0":"Toko Sepeda Salam","shop_name":"Toko Sepeda Salam","1":"Jl.Wachid Hasyim 19","address":"Jl.Wachid Hasyim 19","2":"0274374913","phone_number":"0274374913"},{"0":"AB Bike","shop_name":"AB Bike","1":"Jl. HOS Cokroaminoto No.45","address":"Jl. HOS Cokroaminoto No.45","2":"0274618027","phone_number":"0274618027"},{"0":"Indo Jaya Sakti","shop_name":"Indo Jaya Sakti","1":"Jl. Hos Cokroaminoto No. 157 B","address":"Jl. Hos Cokroaminoto No. 157 B","2":"0274620188","phone_number":"0274620188"},{"0":"Toko Sepeda Rodalink","shop_name":"Toko Sepeda Rodalink","1":"Jl. Laskda Adisucipto Km 6 No. 155C","address":"Jl. Laskda Adisucipto Km 6 No. 155C","2":"0274487229","phone_number":"0274487229"},{"0":"Pedro Pit Shop (Pusat)","shop_name":"Pedro Pit Shop (Pusat)","1":"Jln. Kebon Agung Km 4,6 Los Danon, Godean","address":"Jln. Kebon Agung Km 4,6 Los Danon, Godean","2":"0816972823","phone_number":"0816972823"},{"0":"Pedro Pit Shop (Cabang)","shop_name":"Pedro Pit Shop (Cabang)","1":"Godean Km 9, Godean","address":"Godean Km 9, Godean","2":"02747171665","phone_number":"02747171665"},{"0":"Pedro Pit Shop (Cabang)","shop_name":"Pedro Pit Shop (Cabang)","1":"Jln. Lingkar Utara (ringroad), Karangnongko, Maguwo, Depok, Sleman","address":"Jln. Lingkar Utara (ringroad), Karangnongko, Maguwo, Depok, Sleman","2":"085729075277","phone_number":"085729075277"},{"0":"Nurhayati Bike","shop_name":"Nurhayati Bike","1":"Jalan Raya Cebongan Sleman","address":"Jalan Raya Cebongan Sleman","2":"-","phone_number":"-"},{"0":"Love Sepeda","shop_name":"Love Sepeda","1":"Gandok, Gang suryo No.16, Condongcatur, Depok, Sleman","address":"Gandok, Gang suryo No.16, Condongcatur, Depok, Sleman","2":"085743919166","phone_number":"085743919166"}]}

如何通过shop_name获取经度和纬度? 我在代码中犯的错误请帮助我。谢谢你。

1 个答案:

答案 0 :(得分:0)

您可以查看Geocoder.getFromLocationName()javadoc),尽可能多地传递您在JSON结构中的商店地址。

检索到的Address个对象具有可以传递给地图的纬度和经度。