如何在Android应用程序中从Google地图上的标记开始活动?

来源:爱站网时间:2021-11-08编辑:网友分享
爱站技术小编最近遇到一个问题:如何在Android应用程序中从Google地图上的标记开始活动?面对这个问题貌似也没有人能回答我,哈哈,只能老老实实的去查阅资料,现在整理出一份给大家参考。希望大家有兴趣的可以参考了解一下。

问题描述


在此代码中,它显示了地图中唯一未重定向到另一页面的标记

public class ParkingDataProvider {

    private Context mContext;
    // Lookup parking locations in this zip code.
    private HashMap> mLocationLookup;
    private ProgressDialog progressDialog;

    public ParkingDataProvider(Context thisContext) {

        mContext = thisContext;
        progressDialog = new ProgressDialog(mContext);
        getFromServer();
        constructMockParkingLocations();
    }

    public void constructMockParkingLocations () {

        mLocationLookup = new HashMap>();
        LatLng parkingSpot = new LatLng(13.012935, 80.235724 );
        String address ="Near IST dept,Anna University";
        String name = ("parking 1");
        ParkingData pData = new ParkingData(name, address, parkingSpot);


        LatLng parkingSpot2 = new LatLng(13.010753, 80.234380 );
        String address2 ="Main Entrance,Anna University";
        String name2 = ("parking 2");
        ParkingData pData2 = new ParkingData(name2, address2, parkingSpot2);

        LatLng parkingSpot3 = new LatLng(13.040973, 80.227094 );
        String address3 ="T Nagar";
        String name3 = ("parking 3");
        ParkingData pData3 = new ParkingData(name3, address3, parkingSpot3);



        List allLocations = new ArrayList();
        allLocations.add(pData);
        allLocations.add(pData2);
        allLocations.add(pData3);


        LatLng currentLocation = new LatLng(13.012398, 80.240122);
        mLocationLookup.put(getZipCode(currentLocation), allLocations);
    }

    public String getZipCode(LatLng currentLocation) {
        String zipCode = "600025";
        Geocoder geocoder = new Geocoder(mContext, Locale.getDefault());
        try {
            List
addresses = geocoder.getFromLocation(currentLocation.latitude, currentLocation.longitude, 1); zipCode = addresses.get(0).getPostalCode(); } catch (Exception e) { } return zipCode; } public String getZipCode(Location currentLocation) { String zipCode = "600025"; Geocoder geocoder = new Geocoder(mContext, Locale.getDefault()); try { List
addresses = geocoder.getFromLocation(currentLocation.getLatitude(), currentLocation.getLongitude(), 1); zipCode = addresses.get(0).getPostalCode(); } catch (Exception e) { } return zipCode; } public List getParkingData(Location currentLocation) { if(mLocationLookup.containsKey(getZipCode(currentLocation))) { return mLocationLookup.get(getZipCode(currentLocation)); } List parkingEmptyList = new ArrayList(); return parkingEmptyList; } public List getParkingLocations(Location currentLocation) { List allLocations = new ArrayList(); if(mLocationLookup.containsKey(getZipCode(currentLocation))) { List result = mLocationLookup.get(getZipCode(currentLocation)); for(int i = 0; i getParkingAddresses(Location currentLocation) { List results = new ArrayList(); if(mLocationLookup.containsKey(getZipCode(currentLocation))) { List result = mLocationLookup.get(getZipCode(currentLocation)); for(int i = 0; i getParkingLocationNames(Location currentLocation) { List results = new ArrayList(); if(mLocationLookup.containsKey(getZipCode(currentLocation))) { List parkingDataList = mLocationLookup.get(getZipCode(currentLocation)); for(int i = 0; i parkingDataList = mLocationLookup.get(getZipCode(currentLocation)); distance = new double[parkingDataList.size()]; // convert current location into LatLng LatLng mylocation = new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude()); for(int i = 0; i () { @Override public void onResponse(String response) { progressDialog.dismiss(); try { JSONObject jsonObject = new JSONObject(response); System.out.println("RESPONSE"+jsonObject.toString()); //Toast.makeText(getApplicationContext(), jsonObject.getString("message"), Toast.LENGTH_LONG).show(); } catch (JSONException e) { e.printStackTrace(); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { progressDialog.hide(); //Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_LONG).show(); } }) { @Override protected Map getParams() throws AuthFailureError { Map params = new HashMap(); params.put("zipcode", "600025"); return params; } }; // RequestHandler.getInstance(this).addToRequestQueue(stringRequest); RequestQueue requestQueue = Volley.newRequestQueue(mContext); requestQueue.add(stringRequest); } }

思路:


我认为此代码可能会对您有所帮助,这是标记信息对话框单击的单击事件

map.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
    @Override
    public void onInfoWindowClick(Marker marker) {

        startActivity(MapActivity.this,HomeActivity.class);
    }
});

 以上内容就是爱站技术频道小编为大家分享的如何在Android应用程序中从Google地图上的标记开始活动?,看完以上分享之后,大家应该都知道怎么操作了吧。

上一篇:使用多个准备好的语句JDBC时候要怎么操作?

下一篇:依靠硬币翻转的while循环的预期运行时间是多少?

您可能感兴趣的文章

相关阅读

热门软件源码

最新软件源码下载