使用?进行改装时的查询参数?android中的谷歌地图
当我在改型中使用查询参数访问链接url(如第一个链接)时,我遇到改型问题,而我得到的链接url(如第二个链接url)使用?进行改装时的查询参数?android中的谷歌地图,android,google-maps,retrofit,Android,Google Maps,Retrofit,当我在改型中使用查询参数访问链接url(如第一个链接)时,我遇到改型问题,而我得到的链接url(如第二个链接url) 谢谢你 创建一个latlong类 class LatLng { private double lat; private double lng; @Override public String toString() { return String.format("%.1f,%.1f", lat, lng); } } 服务式 public interfac
谢谢你 创建一个latlong类
class LatLng {
private double lat;
private double lng;
@Override public String toString() {
return String.format("%.1f,%.1f", lat, lng);
}
}
服务式
public interface AddressService{
@GET("geocode/json")
Call<AddressResponse> getAddressWithCoordinator(@Query("latlng") LatLng latlng);
}
呼叫请求
Call<AddressResponse> requestCall = restAdapter.getAddressWithCoordinator(LatLng.valueOf(31.26, -94.74));
模型应该是这样的
import com.google.gson.annotations.SerializedName;
import java.util.List;
public class AddressResponse{
@SerializedName("results")
private List<ResultsItem> results;
@SerializedName("status")
private String status;
public void setResults(List<ResultsItem> results){
this.results = results;
}
public List<ResultsItem> getResults(){
return results;
}
public void setStatus(String status){
this.status = status;
}
public String getStatus(){
return status;
}
public class AddressComponentsItem{
@SerializedName("types")
private List<String> types;
@SerializedName("short_name")
private String shortName;
@SerializedName("long_name")
private String longName;
public void setTypes(List<String> types){
this.types = types;
}
public List<String> getTypes(){
return types;
}
public void setShortName(String shortName){
this.shortName = shortName;
}
public String getShortName(){
return shortName;
}
public void setLongName(String longName){
this.longName = longName;
}
public String getLongName(){
return longName;
}
}
public class Geometry{
@SerializedName("viewport")
private Viewport viewport;
@SerializedName("location")
private Location location;
@SerializedName("location_type")
private String locationType;
public void setViewport(Viewport viewport){
this.viewport = viewport;
}
public Viewport getViewport(){
return viewport;
}
public void setLocation(Location location){
this.location = location;
}
public Location getLocation(){
return location;
}
public void setLocationType(String locationType){
this.locationType = locationType;
}
public String getLocationType(){
return locationType;
}
}
public class Location{
@SerializedName("lng")
private double lng;
@SerializedName("lat")
private double lat;
public void setLng(double lng){
this.lng = lng;
}
public double getLng(){
return lng;
}
public void setLat(double lat){
this.lat = lat;
}
public double getLat(){
return lat;
}
}
public class ResultsItem{
@SerializedName("formatted_address")
private String formattedAddress;
@SerializedName("types")
private List<String> types;
@SerializedName("geometry")
private Geometry geometry;
@SerializedName("address_components")
private List<AddressComponentsItem> addressComponents;
@SerializedName("place_id")
private String placeId;
public void setFormattedAddress(String formattedAddress){
this.formattedAddress = formattedAddress;
}
public String getFormattedAddress(){
return formattedAddress;
}
public void setTypes(List<String> types){
this.types = types;
}
public List<String> getTypes(){
return types;
}
public void setGeometry(Geometry geometry){
this.geometry = geometry;
}
public Geometry getGeometry(){
return geometry;
}
public void setAddressComponents(List<AddressComponentsItem> addressComponents){
this.addressComponents = addressComponents;
}
public List<AddressComponentsItem> getAddressComponents(){
return addressComponents;
}
public void setPlaceId(String placeId){
this.placeId = placeId;
}
public String getPlaceId(){
return placeId;
}
}
public class Viewport{
@SerializedName("southwest")
private Location southwest;
@SerializedName("northeast")
private Location northeast;
public void setSouthwest(Location southwest){
this.southwest = southwest;
}
public Location getSouthwest(){
return southwest;
}
public void setNortheast(Location northeast){
this.northeast = northeast;
}
public Location getNortheast(){
return northeast;
}
}
}
你的基本url是什么?我想在你的基本url中有/geocode/json…我的基本url就像你在url/geocode/json之后看到的那样?latlng=。。。你一定有一个朋友吗?但是它将这个url转换为url/geocode/json/?latlng=…我不能使用latlng.valueOflat,lng@user7408943您有字符串吗?我有两个值Lat和Lng,但当创建LatLng对象并将其传递到参数时,它不起作用。您可以发布错误、响应或异常中得到的结果吗?这是AddressResponse模型的问题:
import com.google.gson.annotations.SerializedName;
import java.util.List;
public class AddressResponse{
@SerializedName("results")
private List<ResultsItem> results;
@SerializedName("status")
private String status;
public void setResults(List<ResultsItem> results){
this.results = results;
}
public List<ResultsItem> getResults(){
return results;
}
public void setStatus(String status){
this.status = status;
}
public String getStatus(){
return status;
}
public class AddressComponentsItem{
@SerializedName("types")
private List<String> types;
@SerializedName("short_name")
private String shortName;
@SerializedName("long_name")
private String longName;
public void setTypes(List<String> types){
this.types = types;
}
public List<String> getTypes(){
return types;
}
public void setShortName(String shortName){
this.shortName = shortName;
}
public String getShortName(){
return shortName;
}
public void setLongName(String longName){
this.longName = longName;
}
public String getLongName(){
return longName;
}
}
public class Geometry{
@SerializedName("viewport")
private Viewport viewport;
@SerializedName("location")
private Location location;
@SerializedName("location_type")
private String locationType;
public void setViewport(Viewport viewport){
this.viewport = viewport;
}
public Viewport getViewport(){
return viewport;
}
public void setLocation(Location location){
this.location = location;
}
public Location getLocation(){
return location;
}
public void setLocationType(String locationType){
this.locationType = locationType;
}
public String getLocationType(){
return locationType;
}
}
public class Location{
@SerializedName("lng")
private double lng;
@SerializedName("lat")
private double lat;
public void setLng(double lng){
this.lng = lng;
}
public double getLng(){
return lng;
}
public void setLat(double lat){
this.lat = lat;
}
public double getLat(){
return lat;
}
}
public class ResultsItem{
@SerializedName("formatted_address")
private String formattedAddress;
@SerializedName("types")
private List<String> types;
@SerializedName("geometry")
private Geometry geometry;
@SerializedName("address_components")
private List<AddressComponentsItem> addressComponents;
@SerializedName("place_id")
private String placeId;
public void setFormattedAddress(String formattedAddress){
this.formattedAddress = formattedAddress;
}
public String getFormattedAddress(){
return formattedAddress;
}
public void setTypes(List<String> types){
this.types = types;
}
public List<String> getTypes(){
return types;
}
public void setGeometry(Geometry geometry){
this.geometry = geometry;
}
public Geometry getGeometry(){
return geometry;
}
public void setAddressComponents(List<AddressComponentsItem> addressComponents){
this.addressComponents = addressComponents;
}
public List<AddressComponentsItem> getAddressComponents(){
return addressComponents;
}
public void setPlaceId(String placeId){
this.placeId = placeId;
}
public String getPlaceId(){
return placeId;
}
}
public class Viewport{
@SerializedName("southwest")
private Location southwest;
@SerializedName("northeast")
private Location northeast;
public void setSouthwest(Location southwest){
this.southwest = southwest;
}
public Location getSouthwest(){
return southwest;
}
public void setNortheast(Location northeast){
this.northeast = northeast;
}
public Location getNortheast(){
return northeast;
}
}
}