Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ariel 8 posts 88 karma points
    Aug 27, 2015 @ 19:49
    Ariel
    0

    Google Maps Coordinates error

    Could someone help me with this error emitted when I want to pass the coordinates to display the map throws this error Compiler Error Message: CS0103: The name 'latLng' does not exist in the current context

    enter image description here

    If I put the fixed coordinates, goes perfectly. But I can't when it's for each one of the map.

    enter image description here

  • MrFlo 159 posts 403 karma points
    Aug 28, 2015 @ 07:52
    MrFlo
    0

    Hi Ariel,

    You could just add a check for not null value or in your foreach ?

  • Ariel 8 posts 88 karma points
    Aug 28, 2015 @ 16:36
    Ariel
    0

    Hi Florent

    Thanks for replying Could you give me an example please. This control will allow me to pass the value to var mapOptions and see the map?

    Thanks

  • MrFlo 159 posts 403 karma points
    Aug 30, 2015 @ 15:22
    MrFlo
    0

    Hi Ariel,

    Actually the plugin you are trying to use doesn't seem to be working well with version 7. I am using this one : AngularGoogleMap It's working well. If you setup the coordinates manually don't forget to setup a zoom level or it's not saved properly.

    With this kind of code:

    @{
        var lat = CurrentPage.Map.Latitude;
        var lng = CurrentPage.Map.Longitude;
        var zoom = CurrentPage.Map.Zoom;
    }
    
  • Ariel 8 posts 88 karma points
    Sep 01, 2015 @ 18:20
    Ariel
    0

    Hello MrFlo: I'm using the "Google Maps Property Editor w / Google Places Autocomplete lookup" package and says it has compatibility with version 7.2 of Umbraco. The map I can see but with fixed coordinates, the problem is when I try to pass the coordinates of each umbraco CONTENT'maps .

    Thanks again

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Sep 01, 2015 @ 18:29
    Dirk De Grave
    100

    you're defining and assigning latLng variable in foreach, whereas you try to use that var outside of the foreach (therefore generating an error)

    Move definition of latLng just below Layout statement

    @{ Layout = "Master.cshtml"; GMapsLocation latLng = null; }

    and remove var from

    @{ foreach(...) { var latLng = ... } }

    and you won't get that error anymore.

    Cheers, Dirk

  • Ariel 8 posts 88 karma points
    Sep 01, 2015 @ 21:48
    Ariel
    0

    Dirk:

    When I try to define the variable as null GMapsLocation latLng = null; It gives me the following error: CS0037 Can not convert null to 'GMapsLocation' because it is a value type that does not accept null values

    Cheers, Ariel

  • Ariel 8 posts 88 karma points
    Oct 15, 2015 @ 17:36
    Ariel
    0

    Hi Dirk: Sorry I did not reply earlier. I could solved this, initialize the variable var direcc = Model.Content.GetPropertyValue("direccion");, I don't know if it's the best way but I could fix it. Thank you and MrFlo for your help.

    After this mistake I had, I had a problem with coordinates, showed me the comma instead of a point. And it solved this way Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US");

    GMapsValueConverter.cs
    
    using System;
    using System.Collections.Generic;
    using System.Globalization;
    using System.Linq;
    using System.Web;
    using Umbraco.Core.Models.PublishedContent;
    using Umbraco.Core.PropertyEditors;
    using System.Threading;
    
    public class GMapsValueConverter : PropertyValueConverterBase
    {
    
        public override bool IsConverter(PublishedPropertyType propertyType)
        {
            return "Netaddicts.GMaps".Equals(propertyType.PropertyEditorAlias);
        }
    
        public override object ConvertDataToSource(PublishedPropertyType propertyType, object source, bool preview)
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
    
            if (source == null || string.IsNullOrWhiteSpace(source.ToString()))
            {
                return null;
            }
    
            var coordinates = source.ToString().Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
            //string[] coordinates = source.ToString().Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
    
            return new GMapsLocation
            {
                Latitude = decimal.Parse(coordinates[0], CultureInfo.InvariantCulture),
                Longitude = decimal.Parse(coordinates[1], CultureInfo.InvariantCulture)
            };
        }
    }
    
  • MrFlo 159 posts 403 karma points
    Sep 01, 2015 @ 20:39
    MrFlo
    0

    I haven't see that one. @Dirk Well spoted!

Please Sign in or register to post replies

Write your reply to:

Draft