It is not possible to implicitly convert type "Google.Type.LatLng to "GoogleMaps.LocationServices.MatPoint". witch c#

Robson Amaral 1 Reputation point
2022-01-02T22:52:08.183+00:00

I'm needing to return Latidute and Longitude via an address, however I'm getting a type-conversion error on the return latLng line;

My code:

 public MapPoint GetLatLongFromAddress(AddressData address)
        {
            return GetLatLongFromAddress(address);
        }

        private MapPoint GetLatLongFromAddress(string address)
        {
            var locationService = new GoogleLocationService();
            var point = locationService.GetLatLongFromAddress(address);

            var latidute= point.Latidute;
            var longitude = point.Longitude;

            var latLng = new LatLng()
            {
                Latidute = latidute,
                Longitude = longitude
            };

            return latLng;
        }
Developer technologies ASP.NET ASP.NET Core
Developer technologies ASP.NET Other
Developer technologies C#
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2022-01-03T01:33:03.08+00:00

    Hi @Robson Amaral ,

    It is not possible to implicitly convert type "Google.Type.LatLng to "GoogleMaps.LocationServices.MatPoint".

    The error is clear, you can't implicitly convert type "Google.Type.LatLng to "GoogleMaps.LocationServices.MatPoint".

    If you want to return a LatLng object, change the return data type as below:

         public LatLng GetLatLongFromAddress(AddressData address)  
         {  
             return GetLatLongFromAddress(address);  
         }  
         private LatLng GetLatLongFromAddress(string address)  
         {  
             var locationService = new GoogleLocationService();  
             var point = locationService.GetLatLongFromAddress(address);  
      
             var latidute= point.Latidute;  
             var longitude = point.Longitude;  
      
             var latLng = new LatLng()  
             {  
                 Latidute = latidute,  
                 Longitude = longitude  
             };  
      
             return latLng;  
         }  
    

    If you want to return a MatPoint object, in the GetLatLongFromAddress method, you should create a new MatPoint instance and return it:

         public MapPoint GetLatLongFromAddress(AddressData address)  
         {  
             return GetLatLongFromAddress(address);  
         }  
      
         private MapPoint GetLatLongFromAddress(string address)  
         {  
             var locationService = new GoogleLocationService();  
             var point = locationService.GetLatLongFromAddress(address);  
      
             var latidute= point.Latidute;  
             var longitude = point.Longitude;  
      
             var latLng = new MatPoint()  
             {  
                 Latidute = latidute,  
                 Longitude = longitude  
             };  
      
             return latLng;  
         }  
    

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,
    Dillion

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.