start navigating to position which is stored in database

后端 未结 3 715
孤城傲影
孤城傲影 2020-12-22 09:17

I have an application where I am getting the latitude and longitude coordinates.

I want , when to press a button to start navigating to that position .

Now ,

相关标签:
3条回答
  • 2020-12-22 10:00

    In the example below ImplLocationService is a class/service within my application that is providing the latitude and longitude coordinates of the current location within the device. The Location class is similar to Android's offering but is slightly different and is providing the destination latitude and longitude coordinates. If you were to pull these values from a database, the approach below is the same.

            Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
                   Uri.parse("http://maps.google.com/maps?saddr=" + 
                   ImplLocationService.getCurrentLocation().getLatitude() + "," + 
                   ImplLocationService.getCurrentLocation().getLongitude() + "&daddr=" + 
                   location.getPoint().latitude + "," + location.getPoint().longitude));
            startActivity(intent);
    
    0 讨论(0)
  • 2020-12-22 10:12

    While storing the lat and long store it in this way...

    String mylocation=latitude + ":" + longitude;
    

    And while retriving it

    String latitude = mylocation.subString(0, myLocation.indexOf(":") -  1 );
    String longitude = mylocation.subString(myLocation.indexOf(":"));
    

    and pass it as

    j.putExtra("lon", longitude);
    j.putExtra("lat", latitude);
    
    0 讨论(0)
  • 2020-12-22 10:20

    one possible way is to store your latitude and longitude values in shared preferences.

    -To store values you can use

     SharedPreferences sp = getSharedPreferences("MyPrefs", MODE_PRIVATE);
    
            Editor editor = sp.edit();
            editor.putString("mytext", text);
            editor.commit();
    

    -and to retrive those values you can use

    String value = prefs.getString("MyPrefs, "mytext");
    

    in your code your are storing latitude and longitudes in double do not forget to convert them in toString()...

    hope this helps

    0 讨论(0)
提交回复
热议问题